Name
SUBDATE( )
Synopsis
SUBDATE(date
, INTERVALvalue
type
)
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
).
Get MySQL in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.