DateTime 格式相比较,timestampdiff() 函数的运用
示例:查询 tbRecords 表中,dtModifyTime 字段记录的数据 距 NOW() 在 5 ~ 10 分钟 的记录:
SELECT * FROM tbRecords WHERE timestampdiff(minute,dtModifyTime,NOW()) > 5 AND timestampdiff(minute,dtModifyTime,NOW()) < 10;
MySQL timestampadd() 函数类似于 date_add()。
select timestampdiff(year,'2002-05-01','2001-01-01'); ——结果为 -1
select timestampdiff(day ,'2002-05-01','2001-01-01'); ——结果为 -485
select timestampdiff(hour,'2008-08-08 12:00:00','2008-08-08 00:00:00'); ——结果为 -12
select datediff('2008-08-08 00:00:00', '2008-08-01 12:00:00'); ——结果为 7
select datediff('2008-08-08 12:00:00', '2008-08-01 00:00:00'); ——结果为 7