怎样比较两个时间相差多少  (有没有函数可以直接返回两个时间相差的天数)?

解决方案 »

  1.   

    mysql> SELECT DATE_SUB("1998-01-01 00:00:00",
                           INTERVAL "1 1:1:1" DAY_SECOND);
            -> 1997-12-30 22:58:59
    mysql> SELECT DATE_SUB("1998-01-02", INTERVAL 31 DAY);
            -> 1997-12-02
      

  2.   

    以下摘自 MySQL 5.1 Reference ManualDATEDIFF(expr1,expr2) DATEDIFF() returns expr1 – expr2 expressed as a value in days from one date to the other. expr1 and expr2 are date or date-and-time expressions. Only the date parts of the values are used in the calculation. 
    == 思想重于技巧 ==
      

  3.   

    此外还有DATE_SUB()
    DATEDIFF()(v4.1.1)
    TIMEDIFF()(v4.1.1)
    详见 MySQL 5.1 Reference Manual
    == 思想重于技巧 ==