SELECT TIMESTAMPDIFF(类型,开始时间,结束时间)
秒数差:
SELECT TIMESTAMPDIFF(SECOND,'2022-01-01 00:00:00',DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S'))
分钟差:
SELECT TIMESTAMPDIFF(MINUTE,'2022-01-01 00:00:00',DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S'))
小时差:
SELECT TIMESTAMPDIFF(HOUR,'2022-01-01 00:00:00 00:00:00',DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S'))
天数差:
SELECT TIMESTAMPDIFF(DAY,'2022-01-01 00:00:00',DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S'))
周数差:
SELECT TIMESTAMPDIFF(WEEK,'2022-01-01 00:00:00',DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S'))
季度差:
SELECT TIMESTAMPDIFF(QUARTER,'2022-01-01 00:00:00',DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S'))
月数差:
SELECT TIMESTAMPDIFF(MONTH,'2022-01-01 00:00:00',DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S'))
年数差:
SELECT TIMESTAMPDIFF(YEAR,'2022-01-01 00:00:00',DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S'))
获取当前日期:
SELECT NOW()
更换下面标签 增加对应类型的数值
FRAC_SECOND 毫秒、SECOND 秒、MINUTE 分钟、HOUR 小时、DAY 天、WEEK 星期、MONTH 月、QUARTER 季度、YEAR 年
例:
当前日期增加一天:
SELECT DATE_SUB(NOW(),INTERVAL -1 DAY)
当前日期减少一天:
SELECT DATE_SUB(NOW(),INTERVAL 1 DAY)