TIMESTAMPDIFF(时间粒度, 开始时间, 结束时间)
1、时间粒度:
秒:SECOND
分:MINUTE
时:HOUR
天:DAY
周:WEEK
季度:QUARTER
月:MONTH
年:YEAR
2、计算相差的时间粒度数,实例:
秒数:
SELECT TIMESTAMPDIFF(SECOND,'2000-06-15 00:00:00', DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S'))
小时数
SELECT TIMESTAMPDIFF(HOUR,'1993-03-23 00:00:00 00:00:00', DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S'))
相差天数
SELECT TIMESTAMPDIFF(DAY,'1993-03-23 00:00:00', DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S'))
相差的周数:
SELECT TIMESTAMPDIFF(WEEK,'1993-03-23 00:00:00', DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S'))
季度数:
SELECT TIMESTAMPDIFF(QUARTER,'1993-03-23 00:00:00', DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S'))
月数:
SELECT TIMESTAMPDIFF(MONTH,'1993-03-23 00:00:00', DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S'))
年数(年龄):
SELECT TIMESTAMPDIFF(YEAR,'1993-03-23 00:00:00', DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S'))
3、获取当前时间NOW()
或CURDATE()
SELECT DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S')
标签:-%,00,FORMAT,时间差,日期,mysql,DATE,NOW,SELECT
From: https://www.cnblogs.com/lanjianhua/p/18354830