How to Subtract Years

Subtract days, months, years from a date in JavaScript

You are simply reducing the values from a number. So substracting 6 from 3 (date) will return -3 only.

You need to individually add/remove unit of time in date object

var date = new Date();
date.setDate( date.getDate() - 6 );
date.setFullYear( date.getFullYear() - 1 );
$("#searchDateFrom").val((date.getMonth() ) + '/' + (date.getDate()) + '/' + (date.getFullYear()));

How to subtract years?

The easiest thing to do is to convert it into POSIXlt and subtract 2 from the years slot.

> d <- as.POSIXlt(as.Date('2010/03/17'))
> d$year <- d$year-2
> as.Date(d)
[1] "2008-03-17"

See this related question: How to subtract days in R?.

Is it possible to subtract days, months or years from current date in swift

You should use Calendar to do these calculations instead of hard coding 86400 for a day.

if let date = Calendar.current.date(byAdding: .day, value: -7, to: Date()) {
// Use this date
}

How to subtract years from sysdate


WHERE dob < add_months( trunc(sysdate), -12*20 );

would work assuming that you want to ignore the time component of sysdate.

How to subtract a year from the datetime?


var myDate = DateTime.Now;
var newDate = myDate.AddYears(-1);

Subtract a year from a datetime column in pandas

You can use DateOffset to achieve this:

In[88]:
df['NEW_DATE'] = df['ACC_DATE'] - pd.DateOffset(years=1)
df

Out[88]:
ACC_DATE NEW_DATE
index
538 2006-04-07 2005-04-07
550 2006-04-12 2005-04-12

How to subtract a year from a date stored in a variable in shell script?

Played around with it. This seems to work:

as_of_dt='2016-01-01'
as_of_dt_prev_year=$(date --date="${as_of_dt} -1 year" +'%Y-%m-%d')
echo $as_of_dt_prev_year

Note the double quotes that are needed for variable substitution to work.



Related Topics



Leave a reply



Submit