Hi,
I have the time taken to do a task stored like this:
01:15:20 // this is 1 hour 15 minutes and 20 seconds
13:30:30 // this is 13 hours 30 minutes and 30 seconds
how can i add these two times up and calculate the total time taken, to give the answer
14:45:50 // 14 hours 45 minutes and 50 seconds
????????????????
adding time
Moderator: General Moderators
i added them up in variables
$hours
$minutes
$seconds
and used the below code to add and manipulate the data but it goes over 60 minutes... what am i doing wrong:
for example it says:
21 Hours 66 Mins 26 Seconds
$hours
$minutes
$seconds
and used the below code to add and manipulate the data but it goes over 60 minutes... what am i doing wrong:
for example it says:
21 Hours 66 Mins 26 Seconds
Code: Select all
<?php echo ($hours + (int)($minutes/60)). ' Hours '.((int)($minutes%60) + (int)($seconds/60)).' Mins '.(int)($seconds%60).' Seconds '; ?>- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
I have the total time taken stored in the database like 01:10:12, 1 hour, 10 minutes and 12 seconds, so i just keep adding the values to the variables like this:
I found a class which does exactly what i needed because i total the hours, minutes and seconds - i took you advice and worked out the seconds using the following class:
http://aidan.dotgeek.org/repos/?file=Duration.php
Thanks for the tip..... too early for me to think and its friday
Code: Select all
<?php
$hours = $hours + date("G",strtotime($tt_total_time_taken));
$minutes = $minutes + date("i",strtotime($tt_total_time_taken));
$seconds = $seconds + date("s",strtotime($tt_total_time_taken));
?>I found a class which does exactly what i needed because i total the hours, minutes and seconds - i took you advice and worked out the seconds using the following class:
http://aidan.dotgeek.org/repos/?file=Duration.php
Thanks for the tip..... too early for me to think and its friday