如果在DATEDIFF()函数的参数中同时包含日期和时间组件,MySQL会返回什么?
MySQL DATEDIFF()函数也适用于日期和时间值,但它会忽略时间值。因此,即使在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()函数在计算日期差值时如何忽略时间值。
广告