|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-04-27 20:06 UTC] mwu at oxid8 dot com
Description:
------------
This worked prior to php 5.2.9 (at least its working in 5.2.6)
strtotime("+1 Wed",time()) would yield a timestamp that is 1 Wednesday
from the current time. So if the current date is Monday April 27,2009
3pm, then the resulting function would return May 6, 2009 3pm. in 5.2.9
executing this function returns the same timestamp.
Reproduce code:
---------------
function test($sInterval,$iNextDate) {
echo "strtotime(\"$sInterval\",$iNextDate);<br/>";
echo $iNextDate = strtotime($sInterval,$iNextDate) . "<br/>";
echo $iNextDate = strtotime($sInterval,$iNextDate) . "<br/>";
echo $iNextDate = strtotime($sInterval,$iNextDate) . "<br/>";
echo "<br/>";
}
$iNextDate = time();
test("+1 Wed",$iNextDate);
test("+1 day",$iNextDate);
test("+1 week",$iNextDate);
Actual result:
--------------
strtotime("+1 Wed",1240860865);
1240981200
1240981200
1240981200
strtotime("+1 day",1240860865);
1240947265
1241033665
1241120065
strtotime("+1 week",1240860865);
1241465665
1242070465
1242675265
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 17 19:00:01 2025 UTC |
Try fixing your script first. This works: <?php function test($sInterval,$iNextDate) { $iNextDate = strtotime($sInterval,$iNextDate); echo date("r", $iNextDate), "\n"; $iNextDate = strtotime($sInterval,$iNextDate); echo date("r", $iNextDate), "\n"; $iNextDate = strtotime($sInterval,$iNextDate); echo date("r", $iNextDate), "\n"; } $iNextDate = time(); test("+1 Wed",$iNextDate); test("+1 day",$iNextDate); test("+1 week",$iNextDate); ?> And output is as expected: Wed, 29 Apr 2009 00:00:00 +0300 Wed, 29 Apr 2009 00:00:00 +0300 Wed, 29 Apr 2009 00:00:00 +0300 Tue, 28 Apr 2009 23:26:44 +0300 Wed, 29 Apr 2009 23:26:44 +0300 Thu, 30 Apr 2009 23:26:44 +0300 Mon, 04 May 2009 23:26:44 +0300 Mon, 11 May 2009 23:26:44 +0300 Mon, 18 May 2009 23:26:44 +0300