May 2005
Intermediate to advanced
352 pages
14h 39m
English
SUBDATE( )
SUBDATE(date, INTERVALvaluetype)
Use this function to subtract a time
interval from the results of a date or
time datatype column. If a negative value is
given, the interval is added and is equivalent to the
ADDDATE( ) function. This is an alias for the
DATE_SUB( ) function. See DATE_ADD(
) for a table of incremental types.
SELECT SUBDATE(NOW( ), INTERVAL 1 DAY)
AS 'Yesterday',
SUBDATE(NOW( ), INTERVAL -1 DAY)
AS 'Tomorrow';
+---------------------+---------------------+
| Yesterday | Tomorrow |
+---------------------+---------------------+
| 2004-05-09 16:11:56 | 2004-05-11 16:11:56 |
+---------------------+---------------------+As of Version 4.1 of MySQL, for subtracting days the second argument
of the function may simply be the number of days (i.e., just
1 instead of INTERVAL 1
DAY).
Read now
Unlock full access