Page 1 of 1

Adding up accumulated hours

Posted: Fri Aug 14, 2009 9:30 am
by Noobie
Hello everyone!

I've got a list of accumulated hours stored in a MySQL db which I'd like to add together. They're stored as Time type.

So if I have:

01:30:00
01:30:00

I'd like to be able to total them up to 3 hours.

I've been attempting to use a Select query to do the work for me but it's not producing what I want.

Here's the query bit:

Code: Select all

$result = @mysql_query("SELECT SUM(flight_time) as totalflighttime7 from log  WHERE date BETWEEN DATE_SUB( CURDATE( ) ,INTERVAL 7 DAY ) AND CURDATE( ) ");
What I want is for it to look up the flight times over the last 7 days and total them.

So for the above example I'm actually getting 26000 returned (which I assume is 02:60:00) whereas what I want is 03:00:00.

Can anyone point me in the right direction? Should I be using PHP instead of the above select query?

Thanks

Re: Adding up accumulated hours

Posted: Mon Aug 17, 2009 5:50 am
by Noobie
Hi

Thanks for your answer - I'll give it a go and see how I get on.

Would I be better to store the hours in the DB as a different type?

The data in the table originally came from a .csv where the format used for recording time was, effectively, hh:mm.