mysql 计算时间差 天,时间,月份等。mysql 时间日期函数 电脑版发表于:2023/6/25 9:37 ### TIMESTAMPDIFF函数 三个参数。第一个参数是比较的类型:FRAC_SECOND、SECOND、 MINUTE、 HOUR、 DAY、 WEEK、 MONTH、 QUARTER、YEAR几种类型。第二、三参数是时间,后减前 **月份时间差** ``` SELECT TIMESTAMPDIFF(MONTH,'2023-02-13','2023-03-13'); -- 结果:1 SELECT TIMESTAMPDIFF(MONTH,'2023-02-13','2023-03-12'); -- 结果:0 ``` **天时间差** ``` SELECT TIMESTAMPDIFF(DAY,'2023-01-01','2023-01-02'); -- 结果:1 ``` **小时时间差** ``` SELECT TIMESTAMPDIFF(HOUR,'2023-06-24 19:31:43',now()) ```