Name
DATE_ADD( )
Synopsis
DATE_ADD(date
, INTERVALvalue
type
)
This
function extracts time or date information and, thereby, adds time to
the value extracted. It’s synonymous with the
ADDDATE( )
function.
UPDATE appointments SET appt_date = DATE_ADD(appt_date, INTERVAL 1 DAY) WHERE rec_id='1202';
In this example, the appointment date is changed to its current value
plus, one additional day (i.e., we’re postponing the
appointment by one day). If we changed the 1 to a -1, MySQL would
subtract a day instead. The format of value
depends on the type
and is shown in Table 6-1.
Type of increment |
Description |
|
dd |
|
dd hh |
|
dd hh:mm |
|
dd hh:mm:ss |
|
hh |
|
hh:mm |
|
hh:mm:ss |
|
mm |
|
mm:ss |
|
mm |
|
ss |
|
yyyy |
|
yy-mm |
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.