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?
I have tried SELECT Mar1start, Mar1end, DateDiff('n', Mar1start, Mar1end)/60 AS Hours AS Total
I have tried SELECT Mar1start, Mar1end, DateDiff('n', Mar1start, Mar1end)/60 AS Hours
but no luck.
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")
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.
SELECT Sum(DateDiff('n', Mar1start, Mar1end)/60) AS Total
Sorry, I had misunderstood/misread the question.
Using Russell's lead, use this instead:
as you only want it to divide by 60 once, at the end, and not on every row.
SELECT Sum(DateDiff('n', Mar1start, Mar1end))/60 AS Total
good call NightShift58
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...
Works perfect thanks you for always answering my annoying questions. I am learning little by little.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)