Re: [PHP] time calcs
On Mon, 30 Jun 2003 07:31:59 -0500, Wendell Brown wrote: On Sun, 29 Jun 2003 15:19:56 -0400, Larry R. Sieting wrote: I want to output the difference as a difference expressed in time format: 10:05:23 - 09:45:32 = 00:39:51 Try this: ?PHP $tot_time = ($data['end_time'] - $data['start_time']); echo strftime( %H:%M:%S, $end_time ) . - ; echo strftime( %H:%M:%S, $start_time ) . = ; echo gmstrftime( %H:%M:%S, $tot_time ); ? E I used the wrong variables in the previous message. I also assumed that the start and end times are actually TIME and not strings (which appears to be the case since you are subtracting one from the other). If the start and end AREN'T time types you would have to convert them first. You should be able to use 'strtotime' or mktime to convert them to time type. Also, the gmstrtime used above would limit the time to 24 hours. If there is a possibility that the difference in time might be more than 24 hours you can do something like this: printf( %d days %s, (int)($tot_time / 86400), gmstrftime( %H:%M:%S, $tot_time ) ); So, here is what I probably should have posted: ?PHP $tot_time = ($data['end_time'] - $data['start_time']); echo strftime( %H:%M:%S, $data['end_time'] ) . - ; echo strftime( %H:%M:%S, $data['start_time'] ) . = ; printf( %d days %s, (int)($tot_time / 86400), gmstrftime( %H:%M:%S, $tot_time ) ); ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] time calcs
Hello, I am trying to get a time calculation using: $tot_time = ($data['end_time'] - $data['start_time']); The end_time start_time are stored in a db as column type of time. I want to output the difference as a difference expressed in time format: 10:05:23 - 09:45:32 = 00:39:51 Do I need to break the stored time values apart and do calcs on each segment? I am not storing the calculated time. Larry R. Sieting -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] time calcs
On Monday 30 June 2003 03:19, Larry R. Sieting wrote: I am trying to get a time calculation using: $tot_time = ($data['end_time'] - $data['start_time']); The end_time start_time are stored in a db as column type of time. I want to output the difference as a difference expressed in time format: 10:05:23 - 09:45:32 = 00:39:51 Do I need to break the stored time values apart and do calcs on each segment? I am not storing the calculated time. Your DBMS may very well have time date/time functions built-in that can do this for you. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* Include me out. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php