4

I know about DATEDIFF(d, date1, date2), but I am not looking to subtract two dates, rather an amount of days from a date.

For example:

"2010-04-13" - 4 = "2010-04-09"

Is that possible with mySQL?

4 Answers 4

5
date_sub(date,interval 4 day);
2

Yes. See http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_adddate

SELECT DATE_ADD('2008-01-02', 31);

Results in:

'2008-02-02'

To subtract, just use a negative number, or use DATE_SUB

1

This will subtract 2 days from a date in a table, and show both dates.

SELECT
[Date]
,DATEADD(DAY, -2, [Date]) AS [NewDate]
FROM
[YourTable]
-5

yes. Mysql has plenty of date functions. Just google mysql datetime functions and you'll get the list. Date subtraction ones among them

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.