php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48091 strtotime("+1 wed",time()); doesn't work
Submitted: 2009-04-27 20:06 UTC Modified: 2009-05-06 17:30 UTC
From: mwu at oxid8 dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.2.9 OS: CentOS release 5.2 (Final)
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mwu at oxid8 dot com
New email:
PHP Version: OS:

 

 [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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-04-27 20:27 UTC] jani@php.net
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


 [2009-04-27 20:55 UTC] mwu at oxid8 dot com
The output as you see here is not as expected..

When I do this in php 5.2.6, I get this:
Wed, 29 Apr 2009 00:00:00 -0500
Wed, 06 May 2009 00:00:00 -0500
Wed, 13 May 2009 00:00:00 -0500


In php 5.2.9 I get this:
Wed, 29 Apr 2009 00:00:00 +0300
Wed, 29 Apr 2009 00:00:00 +0300
Wed, 29 Apr 2009 00:00:00 +0300
 [2009-05-06 17:30 UTC] mwu at oxid8 dot com
Is this bug going to be addressed? This is a BUG or regression.  The 
behavior is different between 5.2.6 and 5.2.9
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jun 15 15:01:39 2024 UTC