MySQLDATEDIFF()
函数还可以使用日期和时间值,但是会忽略时间值。因此,即使我们在DATEDIFF()
函数中包含时间值,MySQL也会通过忽略时间值来返回日期之间的天数差。
mysql> Select DATEDIFF('2018-10-22 04:05:36','2017-10-22 03:05:45'); +-------------------------------------------------------+ | DATEDIFF('2018-10-22 04:05:36','2017-10-22 03:05:45') | +-------------------------------------------------------+ | 365 | +-------------------------------------------------------+ 1 row in set (0.00 sec) mysql> Select DATEDIFF('2017-10-22 04:05:36','2017-10-22 03:05:45'); +-------------------------------------------------------+ | DATEDIFF('2017-10-22 04:05:36','2017-10-22 03:05:45') | +-------------------------------------------------------+ | 0 | +-------------------------------------------------------+ 1 row in set (0.00 sec)
上面的查询显示了DATEDIFF()
函数如何在计算日期之间的差异时忽略时间值。