note 47154 added to function.strtotime
| From: | RobJenkins at osu1 dot php dot net | Date: | Thu, 04 Nov 2004 18:49:54 +0000 |
| Subject: | note 47154 added to function.strtotime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-79629@lists.php.net to get a copy of this message | ||
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");
----
Manual Page -- http://www.php.net/manual/en/function.strtotime.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+47154
Delete -- http://master.php.net/manage/user-notes.php?action=delete+47154&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47154&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47154&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47154&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47154&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47154&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+47154&report=yes
Search -- http://master.php.net/manage/user-notes.php