days_diff

description

Syntax

INT days_diff(DATETIME enddate, DATETIME startdate)

开始时间到结束时间相差几天,对日期的判断精确到秒,并向下取整数。 区别于datediff,datediff函数对日期的判断精确到天。

example

  1. mysql> select days_diff('2020-12-25 22:00:00','2020-12-24 22:00:00');
  2. +---------------------------------------------------------+
  3. | days_diff('2020-12-25 22:00:00', '2020-12-24 22:00:00') |
  4. +---------------------------------------------------------+
  5. | 1 |
  6. +---------------------------------------------------------+
  7. mysql> select days_diff('2020-12-25 22:00:00','2020-12-24 22:00:01');
  8. +---------------------------------------------------------+
  9. | days_diff('2020-12-24 22:00:01', '2020-12-25 22:00:00') |
  10. +---------------------------------------------------------+
  11. | 0 |
  12. +---------------------------------------------------------+

keywords

  1. days_diff