MYSQL计算日期差和时间差的函数

DATEDIFF:只计算日期差,精确到天数。

用法:DATEDIFF('2015-04-22 23:59:00', '2015-04-20 00:00:00')

TIMESTAMPDIFF:可以计算日期差,也可以计算时间差,可以通过不同的参数精确到天数,小时,分钟,秒。

用法:TIMESTAMPDIFF(DAY, '2015-04-20 23:59:00', '2015-04-22 00:00:00');
TIMESTAMPDIFF(HOUR, '2015-04-22 00:00:00', '2015-04-22 03:00:00');
TIMESTAMPDIFF(MINUTE, '2015-04-22 00:00:00', '2015-04-22 00:10:00');
TIMESTAMPDIFF(SECOND, '2015-04-22 00:00:00', '2015-04-22 00:00:45');

你可能感兴趣的:(日记)