MySQL – How to SUM Time?

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 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>

Try to investigate 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
)

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 2933 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.