ID:               49115
 Updated by:       der...@php.net
 Reported By:      php at davidstockton dot com
 Status:           Bogus
 Bug Type:         Date/time related
 Operating System: Windows XP/Linux
 PHP Version:      5.2.10
 New Comment:

Yup, that's correct. With the "month year" format, we reset the day to
1. 


Previous Comments:
------------------------------------------------------------------------

[2009-07-31 03:55:41] php at davidstockton dot com

I guess my above assumption is not correct either which means there's
something else going on that I don't understand.  For example,

<?php
echo date('F', strtotime('February 2009')), "\n";

echo date('F', strtotime('February 1')), "\n";
?>

Both lines output the expected "February" even though I've not
specified a day of the month in the first scenario but the timestamp
given by strtotime corresponds to February 1, 2009.  If the function
fills in the defaults from the current date, I'd expect to still see
March for the 1st line.)

------------------------------------------------------------------------

[2009-07-31 02:57:44] php at davidstockton dot com

Interesting. So I'd guess that if I run this same test tomorrow, I'll
be seeing

January
March
March
May
May
July
July
August
October
October
December
December

I think I understand why it would be doing this, but it still seems
pretty weird.  Is the assumption that strtotime fills in every part of
the date/time with whatever the current time happens to be correct?)

------------------------------------------------------------------------

[2009-07-30 23:29:17] ras...@php.net

date() is doing what it is supposed to.  You are passing it a timestamp
in March.

strtotime() returns a timestamp in March because you have not been
specific enough.  When you just give it a month and nothing else, it
makes some assumptions.  For example, it takes the current year and the
current date.  So, you are asking strtotime for February 30, 2009 which
actually doesn't exist since February doesn't have 30 days, so it gives
you the closest match which is March 2nd.

Not a bug.  You just have to be more explicit.  Like "February 1"

------------------------------------------------------------------------

[2009-07-30 23:25:53] php at davidstockton dot com

Also, not sure if this is related, but the following code has similar
strange behavior:

for ($i = 1; $i <= 12; $i++) {
    echo date('F', gmmktime(0,0,0,$i)), "<br/>";
}

Output:
--------
January
March
March
April
May
June
July
August
September
October
November
December

Expected:
----------
January
February
March
April
May
June
July
August
September
October
November
December

I'd be happy to open a new defect if it's not related, or to be told
why these are correct behavior.

Thanks.

------------------------------------------------------------------------

[2009-07-30 23:16:45] php at davidstockton dot com

Description:
------------
If I use strtotime on 'February' the resulting timestamp is in March.

Reproduce code:
---------------
echo date('F', strtotime('February'));


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

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


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=49115&edit=1

Reply via email to