php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43472 strtotime("first Sunday" ... does not work in command line
Submitted: 2007-12-01 17:07 UTC Modified: 2008-06-23 14:45 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:0 of 0 (0.0%)
From: phil at goli dot at Assigned:
Status: Wont fix Package: Date/time related
PHP Version: 4.4.7 OS: FreeBSD 6.2-RELEASE-p1
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: phil at goli dot at
New email:
PHP Version: OS:

 

 [2007-12-01 17:07 UTC] phil at goli dot at
Description:
------------
the problem described occurs only in the version 4.4.7

the script below produces the following output when run as a web-script:

$myFirstAdvent: 12-02 
$mySecondAdvent: 12-09 
$myThirdAdvent: 12-16 
$myFourthAdvent: 12-23

the script below produces the following output when run via command line:

$myFirstAdvent: 12-02
$mySecondAdvent: 12-02
$myThirdAdvent: 12-02
$myFourthAdvent: 12-02



Reproduce code:
---------------
<?php
  $myTmp = strtotime("first Sunday", mktime(0, 0, 0, 11, 27, 2007) ); // date("Y", myDST())
  $myFirstAdvent = date("m-d", $myTmp);
  $myTmp = strtotime("next Sunday", $myTmp);
  $mySecondAdvent = date("m-d", $myTmp);
  $myTmp = strtotime("next Sunday", $myTmp);
  $myThirdAdvent = date("m-d", $myTmp);
  $myTmp = strtotime("next Sunday", $myTmp);
  $myFourthAdvent = date("m-d", $myTmp);
  echo '$myFirstAdvent: ' . $myFirstAdvent . "\n";
  echo '$mySecondAdvent: ' . $mySecondAdvent . "\n";
  echo '$myThirdAdvent: ' . $myThirdAdvent . "\n";
  echo '$myFourthAdvent: ' . $myFourthAdvent . "\n";
?>

Expected result:
----------------
if run in the command line it should also the correct dates:

$myFirstAdvent: 12-02 
$mySecondAdvent: 12-09 
$myThirdAdvent: 12-16 
$myFourthAdvent: 12-23


Actual result:
--------------
if run in the command line it displays these dates:

$myFirstAdvent: 12-02
$mySecondAdvent: 12-02
$myThirdAdvent: 12-02
$myFourthAdvent: 12-02

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-06-23 14:25 UTC] danmagicman7 at gmail dot com
The problem is with "next Sunday".  It will not advance to the next Sunday. I ran into this problem as well.
 [2008-06-23 14:31 UTC] danmagicman7 at gmail dot com
For clarification, strtotime will not advance to "Next Sunday" if it is given a date that lands on a Sunday.

Here is a workaround if you are writing something that needs to advance to the next Sunday, but you may not be giving it a date that starts with a sunday every time (in my case something that splits up weeks of a month):

$i was a result of a for loop, in my case.

if(date('D',$your_date) == 'Sun'){
    $sunday_offset = 1;
} else {
     $sunday_offset = 0;
}

$next_sunday = strtotime("next Sunday +" . ($i+$sunday_offset) . "week", $your_date);
 [2008-06-23 14:45 UTC] derick@php.net
We are sorry, but we can not support PHP 4 related problems anymore.
Momentum is gathering for PHP 6, and we think supporting PHP 4 will
lead to a waste of resources which we want to put into getting PHP 6
ready.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC