Is there a way to subtract the number of days from a date in SQL?

I know about DATEDIFF (d, date1, date2), but I do not want to subtract two dates, not the number of days from the date.

For instance:

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

Is this possible with mySQL?

+3
source share
4 answers

date_sub (date, interval 4 days);

+4
source

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, simply use a negative number or use DATE_SUB

+1
source

2 .

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

. Mysql . google mysql datetime functions, .

-4

Source: https://habr.com/ru/post/1740880/


All Articles