note 47154 deleted from function.strtotime by sean
| From: | sean@php.net | Date: | Wed, 08 Dec 2004 19:41:33 +0000 |
| Subject: | note 47154 deleted from function.strtotime by sean | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-81542@lists.php.net to get a copy of this message | ||
Note Submitter: Rob Jenkins
----
Here's a big "gotcha" that bit me today, in migrating to PHP5. There's a major
change (bug?) in PHP 5.0.0 - 5.0.2 with strtotime().
In php 4.x:
date("Y-m-d H:i:s", strtotime("+1 hour"));
returns something like:
2004-11-04 13:33:23
In php 5.0.x:
date("Y-m-d H:i:s", strtotime("+1 hour"));
returns:
2004-11-04 01:00:00
This is because strtotime("now") is now '2004-11-04 00:00:00' instead of the
current datetime. This made a lot of my PHP4 code suddenly not work. It seems that strtotime() now
completely ignores the hours/minutes/seconds portion of the timestamp if you pass one in, also. For
example strtotime("+5 hours", 1099593750) is exactly the same as strtotime("+5
hours", 1099551600)!
My workaround was to prepend the current date/time in front of all my "+x yyyy"
strtotime() calls. So:
$xtime = strtotime("+5 hours");
becomes:
$now = date("Y-m-d H:i:s");
$xtime = strtotime("$now +5 hours");