【MySQL】【11】DATE_SUB() 从日期减去指定的时间间隔
前言:
DATE_SUB(date, INTERVAL expr type):date 是合法的日期表达式,expr 是时间间隔, type是时间类型
正文:
-- 前一年的数据 date_sub(now(), interval 1 year) select * from table where year(created) = year(date_sub(now(), interval 1 year));
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 |
参考博客:
MySQL DATE_SUB() 函数
https://www.w3school.com.cn/sql/func_date_sub.asp