...

View Full Version : php calculate time differance problem



coolumanga
01-18-2012, 12:03 PM
hi i have this code

$sqlstr13="SELECT * FROM barcode WHERE Internal ='$preinternal' ";

$result13= mysql_query($sqlstr13);
$recordinput13= mysql_fetch_array($result13);

$timeeend=$recordinput13['timeB'];

$today2 = date("G:i:s");

so now i`m subtracting

$diff=strtotime($today2)-strtotime($timeeend);

in hear working perfectly for the time differance less than 1 minte

but time differance above 1 min it will give zero

plz help me to solve this problemmmmmmmm

with the code

mlseim
01-18-2012, 03:37 PM
This line:
$today2 = date("G:i:s");

Should be:
$today2=time();

This line:
$diff=strtotime($today2)-strtotime($timeeend);

Change to:
$diff=$today2-strtotime($timeeend);

time() is the UNIX timestamp right now, for your timezone.
Remember that you're using the server timezone unless you specify it otherwise.

The next issue will be the format of $recordinput13['timeB']
Can you show us how one of those values are formated in the column?

The difference between two UNIX timestamps is in seconds (that's the resolution);
So, you might get a difference of 97. That's 97 seconds. Or a negative difference is possible.


.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum