www.webdeveloper.com
Results 1 to 8 of 8

Thread: Count hours total

  1. #1
    Join Date
    Oct 2006
    Posts
    392

    Count hours total

    I have a SQL statment that counts the time and displays the hours and it worked perfect. The only problem I am havinging is I want it to add all the hours worked into one total. Any Ideas on this?

    Code:
    I have tried SELECT Mar1start, Mar1end, DateDiff('n', Mar1start, Mar1end)/60 AS Hours
    FROM March
    I have tried SELECT Mar1start, Mar1end, DateDiff('n', Mar1start, Mar1end)/60 AS Hours AS Total
    FROM March
    but no luck.
    Attach Code

  2. #2
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    You were close... Use:

    TIMEDIFF() (available from MySQL 4.1.1)

    or, for an earlier MySQL version, you could try:

    TIME_FORMAT(FORUNIX_TIMESTAMP(Mar1end) - UNIX_TIMESTAMP(Mar1start), "%H:%i:%s")

  3. #3
    Join Date
    Oct 2006
    Posts
    392
    no that did not work. I have mutiple entrys that it calculates correctly. All I want it to do now is add all the hour togerther for a grand total.

  4. #4
    Join Date
    Feb 2003
    Posts
    2,745
    SELECT Sum(DateDiff('n', Mar1start, Mar1end)/60) AS Total

  5. #5
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    Sorry, I had misunderstood/misread the question.

    Using Russell's lead, use this instead:
    PHP Code:
    SELECT Sum(DateDiff('n'Mar1startMar1end))/60 AS Total 
    as you only want it to divide by 60 once, at the end, and not on every row.

  6. #6
    Join Date
    Feb 2003
    Posts
    2,745


    good call NightShift58


  7. #7
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    It happens every now and then....

    I have to be up just the right number of hours, just the right number of coffees and cigarettes... Before and after that magical point... it's useless...

  8. #8
    Join Date
    Oct 2006
    Posts
    392
    Works perfect thanks you for always answering my annoying questions. I am learning little by little.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles