Surpassing MySQL's TIME value limit of 838:59:59

前端 未结 6 544
南旧
南旧 2020-12-01 14:54

The title might be a bit confusing so allow me to explain. I\'m using a table to record my work logs. Every day I\'ll create an entry stating from what time to what time I h

6条回答
  •  一生所求
    2020-12-01 15:49

    Have a look at timestampdiff which doesn't have the TIME limitation. I.e. something like (untested):

    SELECT CONCAT(
            TIMESTAMPDIFF(HOURS, entry_end_time, entry_start_time), 
            ":",
            MOD(TIMESTAMPDIFF(MINUTES, entry_end_time, entry_start_time),60)
          )
    AS total FROM entry 
    WHERE entry_date BETWEEN '2012-01-01' AND '2012-12-31' AND user_id = 3
    

    The concats not ideal, I'm sure there will be a more elegant solution.

提交回复
热议问题