MySQL - How to SUM times?

前端 未结 5 2138
礼貌的吻别
礼貌的吻别 2020-11-29 12:15

I have a table that contains date-time values in this format:

START

1/13/2009 7:00:00AM

END

5条回答
  •  南笙
    南笙 (楼主)
    2020-11-29 12:54

    Try looking into UNIX_TIMESTAMP and SEC_TO_TIME.

    You would sum up the differences between the timestamps, then use that value (would be in milliseconds) to get the time:

    SELECT SEC_TO_TIME(time_milis / 1000)
    FROM (
       SELECT SUM(UNIX_TIMESTAMP(date1) - UNIX_TIMESTAMP(date2)) as time_milis
       FROM table
    )
    

提交回复
热议问题