SQL DATE_SUB 是一個mySql函數。不象SQL DATE_ADD 函數 增加時間值,SQL DATE_SUB 將從一個日期/時間值中減去一個時間值(時間間隔)。
SQL DATE_SUB 語法
- DATE_SUB(日期表達式, INTERVAL expr type)
| Type 值 |
|---|
| MICROSECOND |
| SECOND |
| MINUTE |
| HOUR |
| DAY |
| WEEK |
| MONTH |
| QUARTER |
| YEAR |
| SECOND_MICROSECOND |
| MINUTE_MICROSECOND |
| MINUTE_SECOND |
| HOUR_MICROSECOND |
| HOUR_SECOND |
| HOUR_MINUTE |
| DAY_MICROSECOND |
| DAY_SECOND |
| DAY_MINUTE |
| DAY_HOUR |
| YEAR_MONTH |
SQL DATE_SUB 范例
- SELECT DATE_SUB('2010-08-12', INTERVAL 3 DAY) AS NewDate
結果: 2010-08-09
2.SELECT DATE_SUB('2010-08-12', INTERVAL '3-2' YEAR_MONTH) AS NewDate
結果: 2007-06-12
3.SELECT DATE_SUB('2011-09-14 2:44:36', INTERVAL '2:26' HOUR_MINUTE) AS NewDate
結果: 2011-09-14 00:18:36
