php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64548 Last Month (feb/march issue)
Submitted: 2013-03-29 15:07 UTC Modified: 2013-03-30 00:50 UTC
From: timothymarois at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: Irrelevant OS:
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: timothymarois at gmail dot com
New email:
PHP Version: OS:

 

 [2013-03-29 15:07 UTC] timothymarois at gmail dot com
Description:
------------
At the moment, because today is March 29th, my script using 

date("F Y",strtotime('-1 Month')) or date("F Y",strtotime('Last Month'))

Shows March 2013 (a few days ago it showed February 2013) I believe this is due 
to  
feb's short days. I did some testing to it, if I where to do 
date("F Y",strtotime('-2 Month')) the output is January 2013, thats current to 
the 
current date. 

This would be a bug due to php's capabilities in resolving actual calendar days.

I've seen postings that "this is not a bug" but it is, you can't have a script 
designed to give calendar day results, and have it given the wrong results out. 
Its incorrect and needs to be resolves. PHP is the software, and the software 
should be patched to give the current calendar days. 

Test script:
---------------
date("F Y",strtotime('Last Month'))

Expected result:
----------------
February 2013

Actual result:
--------------
March 2013

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-03-30 00:50 UTC] rasmus@php.net
Sorry, but this is really not a bug. This is how most UNIX-based tools do 
relative date math. For better or worse, it is the standard. Try it from your 
Linux command line:

$ date
Fri Mar 29 17:16:02 PDT 2013
$ date --date='-1 month' +'Last month was %B?'
Last month was March?

Or in Sqlite:

sqlite> select datetime('2013-03-29', '-1 month');
2013-03-01 00:00:00

We decided to follow convention here. There is a GNU doc on it here:

http://www.gnu.org/software/tar/manual/html_node/Relative-items-in-date-
strings.html#SEC120

And there really is no good answer. 3/29 - 1 month would be 2/29 but that date 
doesn't exist. So, what do you do? Do you subtract 1 month and 1 day and return 
2/28? That's not very precise. Given the fact that there is no right answer 
here, we followed convention. To do proper relative date math you need to be 
more explicit about what you actually want. As in "first day of last month"
 [2013-03-30 00:50 UTC] rasmus@php.net
-Status: Open +Status: Not a bug
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jun 22 09:01:29 2024 UTC