Adding up accumulated hours

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Noobie
Forum Commoner
Posts: 85
Joined: Sun May 15, 2005 11:38 am

Adding up accumulated hours

Post 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
Noobie
Forum Commoner
Posts: 85
Joined: Sun May 15, 2005 11:38 am

Re: Adding up accumulated hours

Post 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.
Post Reply