php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #51447 strtotime(february) returns a date in march after march 28/29
Submitted: 2010-03-31 17:26 UTC Modified: 2010-03-31 17:46 UTC
From: marques at displague dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.3.2 OS:
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: marques at displague dot com
New email:
PHP Version: OS:

 

 [2010-03-31 17:26 UTC] marques at displague dot com
Description:
------------
strtotime("february") gives erratic results based on the current day of the 
month 
and whether or not that day number exists in February.

strtotime("february") should always return the current day as it is found in 
february, or the last day in february.

This is the case for any month where the current day number is not found in the 
requested month.  The last day in a month should be returned if the current day 
is 
not found in that month.

Example:
date(DATE_RFC822,strtotime('june', strtotime("july 31 2010")))  gives July 1. 

Bug #49115 points out this fact for "February" in the form of a bug report.  

This report shows that the problem exists for all months (with better sample 
cases) and I am requesting a change to the accepted behavior in favor of 
something more sensible.

Test script:
---------------
date_default_timezone_set('America/New_York');
print_r(array(
date(DATE_RFC822,strtotime('february', strtotime("january 31 2010"))),
date(DATE_RFC822,strtotime('february', strtotime("february 28 2010"))),
date(DATE_RFC822,strtotime('february', strtotime("march 31 2010"))),
date(DATE_RFC822,strtotime('february', strtotime("april 30 2010"))),
date(DATE_RFC822,strtotime('february', strtotime("may 31 2010"))),
date(DATE_RFC822,strtotime('february', strtotime("june 30 2010"))),
date(DATE_RFC822,strtotime('february', strtotime("july 31 2010"))),
date(DATE_RFC822,strtotime('february', strtotime("august 31 2010"))),
date(DATE_RFC822,strtotime('february', strtotime("september 30 2010"))),
date(DATE_RFC822,strtotime('february', strtotime("october 31 2010"))),
date(DATE_RFC822,strtotime('february', strtotime("november 30 2010"))),
date(DATE_RFC822,strtotime('february', strtotime("december 31 2010"))),
date(DATE_RFC822,strtotime('february', strtotime("january 1 2010"))),
date(DATE_RFC822,strtotime('february', strtotime("february 1 2010"))),
date(DATE_RFC822,strtotime('february', strtotime("march 1 2010"))),
date(DATE_RFC822,strtotime('february', strtotime("april 1 2010"))),
date(DATE_RFC822,strtotime('february', strtotime("may 1 2010"))),
date(DATE_RFC822,strtotime('february', strtotime("june 1 2010"))),
date(DATE_RFC822,strtotime('february', strtotime("july 1 2010"))),
date(DATE_RFC822,strtotime('february', strtotime("august 1 2010"))),
date(DATE_RFC822,strtotime('february', strtotime("september 1 2010"))),
date(DATE_RFC822,strtotime('february', strtotime("october 1 2010"))),
date(DATE_RFC822,strtotime('february', strtotime("november 1 2010"))),
date(DATE_RFC822,strtotime('february', strtotime("december 1 2010"))),
date(DATE_RFC822,strtotime('june', strtotime("july 31 2010"))),
));


Expected result:
----------------
Array
(
    [0] => Sun, 28 Feb 10 00:00:00 -0500
    [1] => Sun, 28 Feb 10 00:00:00 -0500
    [2] => Sun, 28 Feb 10 00:00:00 -0500
    [3] => Sun, 28 Feb 10 00:00:00 -0500
    [4] => Sun, 28 Feb 10 00:00:00 -0500
    [5] => Sun, 28 Feb 10 00:00:00 -0500
    [6] => Sun, 28 Feb 10 00:00:00 -0500
    [7] => Sun, 28 Feb 10 00:00:00 -0500
    [8] => Sun, 28 Feb 10 00:00:00 -0500
    [9] => Wed, 03 Mar 10 00:00:00 -0500
    [10] => Sun, 28 Feb 10 00:00:00 -0500
    [11] => Sun, 28 Feb 10 00:00:00 -0500
    [12] => Mon, 01 Feb 10 00:00:00 -0500
    [13] => Mon, 01 Feb 10 00:00:00 -0500
    [14] => Mon, 01 Feb 10 00:00:00 -0500
    [15] => Mon, 01 Feb 10 00:00:00 -0500
    [16] => Mon, 01 Feb 10 00:00:00 -0500
    [17] => Mon, 01 Feb 10 00:00:00 -0500
    [18] => Mon, 01 Feb 10 00:00:00 -0500
    [19] => Mon, 01 Feb 10 00:00:00 -0500
    [20] => Mon, 01 Feb 10 00:00:00 -0500
    [21] => Mon, 01 Feb 10 00:00:00 -0500
    [22] => Mon, 01 Feb 10 00:00:00 -0500
    [23] => Mon, 01 Feb 10 00:00:00 -0500
    [24] => Wed, 30 Jun 10 00:00:00 -0400
)


Actual result:
--------------
Array
(
    [0] => Wed, 03 Mar 10 00:00:00 -0500
    [1] => Sun, 28 Feb 10 00:00:00 -0500
    [2] => Wed, 03 Mar 10 00:00:00 -0500
    [3] => Tue, 02 Mar 10 00:00:00 -0500
    [4] => Wed, 03 Mar 10 00:00:00 -0500
    [5] => Tue, 02 Mar 10 00:00:00 -0500
    [6] => Wed, 03 Mar 10 00:00:00 -0500
    [7] => Wed, 03 Mar 10 00:00:00 -0500
    [8] => Tue, 02 Mar 10 00:00:00 -0500
    [9] => Wed, 03 Mar 10 00:00:00 -0500
    [10] => Tue, 02 Mar 10 00:00:00 -0500
    [11] => Wed, 03 Mar 10 00:00:00 -0500
    [12] => Mon, 01 Feb 10 00:00:00 -0500
    [13] => Mon, 01 Feb 10 00:00:00 -0500
    [14] => Mon, 01 Feb 10 00:00:00 -0500
    [15] => Mon, 01 Feb 10 00:00:00 -0500
    [16] => Mon, 01 Feb 10 00:00:00 -0500
    [17] => Mon, 01 Feb 10 00:00:00 -0500
    [18] => Mon, 01 Feb 10 00:00:00 -0500
    [19] => Mon, 01 Feb 10 00:00:00 -0500
    [20] => Mon, 01 Feb 10 00:00:00 -0500
    [21] => Mon, 01 Feb 10 00:00:00 -0500
    [22] => Mon, 01 Feb 10 00:00:00 -0500
    [23] => Mon, 01 Feb 10 00:00:00 -0500
    [24] => Thu, 01 Jul 10 00:00:00 -0400
)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-03-31 17:32 UTC] marques at displague dot com
Expected result:
    [9] => Wed, 03 Mar 10 00:00:00 -0500
Should have read:
    [9] => Sun, 28 Feb 10 00:00:00 -0500

I would also revise my "Example:" to show that:
- actual: date(DATE_RFC822,strtotime('june', strtotime("july 31 2010"))) yields 
"...1 Jul 10.." 
- expected: date(DATE_RFC822,strtotime('june', strtotime("july 31 2010"))) 
should yield "...30 Jun 10..."
 [2010-03-31 17:46 UTC] derick@php.net
-Status: Open +Status: Bogus
 [2010-03-31 17:46 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 20:01:29 2024 UTC