Bug #64548 [Opn->Nab]: Last Month (feb/march issue)
Edit report at https://bugs.php.net/bug.php?id=64548&edit=1
ID: 64548
Updated by: rasmus@php.net
Reported by: timothymarois at gmail dot com
Summary: Last Month (feb/march issue)
-Status: Open
+Status: Not a bug
Type: Bug
Package: Date/time related
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
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"
Previous Comments:
------------------------------------------------------------------------
[2013-03-29 15:07:52] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64548&edit=1
Thread (2 messages)