SQL DATE_SUB 是一个mySql函数。不象 增加时间值,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