Name
DATE_SUB( )
Synopsis
DATE_SUB(date
, INTERVALvalue
type
)
Use this function to subtract from the results of a
date
or time
datatype column.
See DATE_ADD( )
for a table of incremental types.
SELECT DATE_SUB(NOW( ), INTERVAL 1 DAY) AS Yesterday; +---------------------+ | Yesterday | +---------------------+ | 2004-05-08 07:05:08 | +---------------------+
This statement was entered on the morning of May 9, a little after 7
a.m. Notice that the time remains unchanged, but the date was reduced
by one day. By placing a negative sign in front of the value the
reverse effect would occur, giving a result of May 10 in this
example. Whatever intervals that can be used with DATE_ADD()
can be used with DATE_SUB( )
.
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.