views:

57

answers:

2

The following code

 echo $lastmoment."<br/>";
echo time();
echo "<br/>";
echo strtotime($lastmoment);

outputs:

2009-12-15 17:40:53 1260876829 1260898853

What's wrong? $lastment is a past time stamp in MySQL, why is strtotime($lastmoment) bigger than time()?

A: 

Because the time() function was may be executed some milliseconds before the $lastmoment.

EDIT: Adding the comment to my thoughts, it might me that, the convert of strtotime() might have failed. Or the date value from the database contains a value e.g. days which the date() does not have. Be sure, that you compare 2 datevalues of the same format.

daemonfire300
$lastmoment was fetched from database, which was a past time stamp.
Steven
$lastmoment's value is fixed.
Steven
Can you show $lastmoment?
Pekka
If strtotime failed, it should throw a -1, and thus Dec 31st 1969. And even if the date value from the DB was more precise, etc, the whole point of strtotime is to convert any date/time to epoch. So even if it was to the millisecond, it would round off to epoch.
Anthony
+1  A: 

If your MySQL server is a different machine, or if the timestamp in $lastmoment was set from a different machine, you could be seeing clock drift. Check the system clocks on the various machines, and see if they agree.

Andrew Barnett
Rats! +1 for figuring that out right before I did!
Anthony