DATE_SUB(date,INTERVAL expr unit) : DATE_SUB : Date Time Functions MySQL TUTORIALS


MySQL TUTORIALS » Date Time Functions » DATE_SUB »

 

DATE_SUB(date,INTERVAL expr unit)


expr is an expression specifying the interval value.

expr is a string.

expr may start with a '-' for negative intervals.

unit is a keyword indicating the units in which the expression should be interpreted.

The following table shows the expected form of the expr argument for each unit value.

unit Value Expected expr Format
MICROSECOND MICROSECONDS
SECOND SECONDS
MINUTE MINUTES
HOUR HOURS
DAY DAYS
WEEK WEEKS
MONTH MONTHS
QUARTER QUARTERS
YEAR YEARS
SECOND_MICROSECOND 'SECONDS.MICROSECONDS'
MINUTE_MICROSECOND 'MINUTES.MICROSECONDS'
MINUTE_SECOND 'MINUTES:SECONDS'
HOUR_MICROSECOND 'HOURS.MICROSECONDS'
HOUR_SECOND 'HOURS:MINUTES:SECONDS'
HOUR_MINUTE 'HOURS:MINUTES'
DAY_MICROSECOND 'DAYS.MICROSECONDS'
DAY_SECOND 'DAYS HOURS:MINUTES:SECONDS'
DAY_MINUTE 'DAYS HOURS:MINUTES'
DAY_HOUR 'DAYS HOURS'
YEAR_MONTH 'YEARS-MONTHS'


mysql>
mysql> select DATE_SUB(curdate(), INTERVAL DAY);
+-------------------------------------+
| DATE_SUB(curdate(), INTERVAL DAY|
+-------------------------------------+
2007-07-21                          |
+-------------------------------------+
row in set (0.00 sec)

mysql>



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .

Follow Navioo On Twitter

MySQL TUTORIALS

 Navioo Date Time Functions
» DATE_SUB