Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: MySQL Time ADD

  1. #1
    Regular Coder
    Join Date
    Jun 2006
    Location
    UK
    Posts
    922
    Thanks
    302
    Thanked 3 Times in 3 Posts

    Question MySQL Time ADD

    Hi

    I am trying to find out the time difference between two cols in my table

    Code:
    select TIMEDIFF(time_out,time_in)  from mytable

    The result is being displayed in multiple rows like


    Code:
    00:19:56
    00:25:22
    01:33:12
    Is there anyway I can sum or add all these rows and display the sum in HH:MM:SS format in one single query (modifying the above query)?


    Thanx in advance

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,079
    Thanks
    2
    Thanked 320 Times in 312 Posts
    Something like this should work -
    Code:
    select SEC_TO_TIME(SUM(TIME_TO_SEC(TIMEDIFF(time_out,time_in)))) as total_time  from mytable
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    Regular Coder
    Join Date
    Jun 2006
    Location
    UK
    Posts
    922
    Thanks
    302
    Thanked 3 Times in 3 Posts
    That worked!

    You are a genius.


    Thanx so much my friend


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •