Page 1 of 1
Elapsed time in php
Posted: Wed Nov 01, 2006 6:24 pm
by laknal
Hi,
I am trying to get time differene between submit time of previous record and start time time next record.
Please see below code:
Code: Select all
<?php
if(!empty($prevTime))
{
$diff = $prevTime - strtotime($row_rsarticle['created_time']);
echo date("Y-m-d H:i:s", $diff);
}
$prevTime = strtotime($row_rsarticle['time_submit']);
?>
Thanks
Posted: Wed Nov 01, 2006 7:07 pm
by feyd
My mind reading skills aren't so hot, can you explain the problem you're having?
Elapsed time in php
Posted: Wed Nov 01, 2006 8:34 pm
by laknal
I am trying to get the elaspsed time between time submit of first records and start of second records.
I am getting date field errors. Example:
1. End record for first record is 10.55.00
2. Start time for second record is 11.55.00
Desired result is 1.00.00.
But I am getting "Warning: date function invalid" error.
Posted: Wed Nov 01, 2006 9:07 pm
by Burrito
you could make it work with a datetime field, but may I suggest you use a unix timestamp instead. It'll make your life much easier.
Elapsed time in php
Posted: Thu Nov 02, 2006 6:47 am
by laknal
Hi,
Both fields are timestamp in MYSQL database.
Is there a function in php to get previous recordset datefield? May be I can do compute that datafield to current recordset datafield.
Thanks.
Posted: Thu Nov 02, 2006 6:58 am
by onion2k
A period of time (eg 2 hours) is not a date. So you can't use the date functions with it.
If you have two timestamps however you can simply subtract the smaller one from the bigger one to get the number of seconds difference, and once you have that it's pretty easy to convert seconds into other time values. For example, divide by 60 for minutes, by 3600 for hours, by 86400 for days and so on.
You'll need to do a bit of coding if you want a mixed format (eg hours, minutes and seconds).