【问题标题】:Getting the difference between two MYSQL datetime columns in seconds [duplicate]在几秒钟内获得两个MYSQL日期时间列之间的差异[重复]
【发布时间】:2012-12-16 15:09:19
【问题描述】:

可能重复:
MYSQL - datetime to seconds

如果我在 mysql 表中有一个 datetime 列,我如何才能以秒为单位获得 NOW() 和该列之间的差异?

【问题讨论】:

    标签: php mysql database datetime


    【解决方案1】:

    通过TIMEDIFF,您可以按秒获得差异

        SELECT TIME_TO_SEC(TIMEDIFF('2007-01-09 10:24:46','2007-01-09 10:23:46'));
    

    或者这个

    SELECT DATEDIFF('2007-12-31 10:02:00','2007-12-30 12:01:01') * 24*60*60;
    // result: 86400 the difference in seconds for days.
    

    或:

     SELECT TIMESTAMPDIFF(SECOND,'2007-12-30 12:01:01','2007-12-31 10:02:00'); 
     // result: 79259  the difference in seconds with the time.
    

    【讨论】:

      【解决方案2】:

      试试这个:SELECT NOW() - my_col AS my_diff

      【讨论】:

        猜你喜欢
        • 2011-04-01
        • 2016-02-11
        • 2018-11-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-19
        相关资源
        最近更新 更多