Start
1/13/2009 7:00:00 AM
End
1/13/2008 2:57:00 PM
I use the’str to date’ function to convert them Date and time format.
How do I calculate the difference between them?
Then summarize it so that it is displayed in total hours (that is, the total number of hours in a week is 40:53).
I am trying the timediff function, but the results are not summarized.
< /div>
UNIX_TIMESTAMP
and SEC_TO_TIME
.
< /p>
You will summarize the difference between the timestamps, and then use the value (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
)
< p>I have a table with date and time values in this format:
Start
1/13/2009 7:00:00 AM
End
1/13/2008 2:57:00 PM
I used the’str to date’ function to convert them to date and time format.
How do I calculate the difference between them?
Then summarize it so that it is displayed in total hours (that is, the total number of hours in a week is 40:53).
I am trying the timediff function, but the results are not summarized.
< /p>
Try to investigate UNIX_TIMESTAMP
and SEC_TO_TIME
.
You will summarize the And then use the value (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
)