Mysql SUBDATE
From w3cyberlearnings
Contents |
MySQL SUBDATE Function
This function synoymps of DATE_SUB() function.
Syntax SUBDATE
- date: is the date string or timestamp
- INTERVAL: key word
- expr: valid number
- unit: DAY, MONTH, YEAR
SUBDATE(date, INTERVAL expr unit);
Format
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:SECONDS.MICROSECONDS' MINUTE_SECOND 'MINUTES:SECONDS' HOUR_MICROSECOND 'HOURS:MINUTES:SECONDS.MICROSECONDS' HOUR_SECOND 'HOURS:MINUTES:SECONDS' HOUR_MINUTE 'HOURS:MINUTES' DAY_MICROSECOND 'DAYS HOURS:MINUTES:SECONDS.MICROSECONDS' DAY_SECOND 'DAYS HOURS:MINUTES:SECONDS' DAY_MINUTE 'DAYS HOURS:MINUTES' DAY_HOUR 'DAYS HOURS' YEAR_MONTH 'YEARS-MONTHS'
Example 1
mysql> SELECT SUBDATE('2012-04-05', INTERVAL 2 DAY); +---------------------------------------+ | SUBDATE('2012-04-05', INTERVAL 2 DAY) | +---------------------------------------+ | 2012-04-03 | +---------------------------------------+ 1 row in set (0.00 sec)
Example 2
mysql> SELECT SUBDATE('2012-04-05', INTERVAL 2 MONTH); +-----------------------------------------+ | SUBDATE('2012-04-05', INTERVAL 2 MONTH) | +-----------------------------------------+ | 2012-02-05 | +-----------------------------------------+ 1 row in set (0.00 sec)
Example 3
mysql> SELECT SUBDATE('2012-04-05', INTERVAL 3 Week); +----------------------------------------+ | SUBDATE('2012-04-05', INTERVAL 3 Week) | +----------------------------------------+ | 2012-03-15 | +----------------------------------------+ 1 row in set (0.00 sec)
Example 4
mysql> SELECT SUBDATE('2012-04-05', INTERVAL 3 QUARTER); +-------------------------------------------+ | SUBDATE('2012-04-05', INTERVAL 3 QUARTER) | +-------------------------------------------+ | 2011-07-05 | +-------------------------------------------+ 1 row in set (0.00 sec)