The event returns a standardized timestamp in the format of "Sat Oct 25 21:55:29 +0000 2008" How can I compare this with the current time in PHP so that it gives me the result in a form like "It has been 15 minutes!" or "It has been three days!" Also, how can I get the current time?
+6
A:
First convert that string to a UNIX timestamp using strtotime():
$event_time = strtotime('Sat Oct 25 21:55:29 +0000 2008');
Then to get the current UNIX timestamp use time():
$current_time = time();
Then get the number of seconds between those timestamps:
$difference = $current_time - $event_time;
And finally use division to convert the number of seconds into number of days or hours or whatever:
$hours_difference = $difference / 60 / 60;
$days_difference = $difference / 60 / 60 / 24;
For more information on calculating relative time, see How do I calculate relative time?.
yjerem
2008-11-01 06:42:51
beat me to it. (ps: gratz on 5000 rep)
nickf
2008-11-01 06:44:23
I reached my limit unfortunately, but thanks :P
yjerem
2008-11-01 06:46:02
If the input date format is fixed, it may be better to use strptime()
Tom Haigh
2008-11-01 23:27:33