mysql timediff to hours

前端 未结 10 1766
我寻月下人不归
我寻月下人不归 2020-12-13 08:47

I\'m Trying to get the timediff from my table and convert it to hours (it\'s for an hourly billed service)

SELECT TIME_TO_SEC(TIMEDIFF(endDate,startDa

10条回答
  •  不思量自难忘°
    2020-12-13 09:20

    You can use UNIX_TIMESTAMP to do the calculation in SELECT query.

    SELECT (UNIX_TIMESTAMP(endDate)-UNIX_TIMESTAMP(startDate))/3600 hour_diff
      FROM tasks
    

    UNIX_TIMESTAMP convert datetime to number of second from epoch. You can substract both timestamp to get difference in second. Divide it with 3600 will give you difference in hour.

提交回复
热议问题