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
Cut() Error - 'Breaks' Are Not Unique
Perform Multiple Paired T-Tests Based on Groups/Categories
R's Read.CSV Prepending 1St Column Name with Junk Text
List for Multiple Plots from Loop (Ggplot2) - List Elements Being Overwritten
Count How Many Values in Some Cells of a Row Are Not Na (In R)
How to Delete a Column by Name in Data.Table
Group by Two Columns in Ggplot2
Set the Size of Ggsave Exactly
How to Deal with "Data of Class Uneval" Error from Ggplot2
Add a Horizontal Line to Plot and Legend in Ggplot2
Smaller Gap Between Two Legends in One Plot (E.G. Color and Size Scale)
Any Suggestions for How to Plot Mixem Type Data Using Ggplot2
How to Use Subscripts in Ggplot2 Legends [R]
Divide Row Value by Aggregated Sum in R Data.Frame
Split Data Frame into Rows of Fixed Size
What You Can Do with a Data.Frame That You Can't with a Data.Table