|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-07-30 23:16 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 08:00:02 2025 UTC |
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.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.)hi.. You have used date("M", mktime(0, 0, 0, $i)) In this issue there is no initialization of date so it took 30 as default initialize date it will check for the availability of the date, if it is available it will consider the month or it will not take month in account. for example you can check the diff with using : date("M", mktime(0, 0, 0, $i,[2011])); it will consider only the month which have 30 and more days - default [30] date("M", mktime(0, 0, 0, $i,30,[2011])); it will consider only the month which have 30 and more days date("M", mktime(0, 0, 0, $i,31,[2011])); it will consider only the month which have 31 and more days date("M", mktime(0, 0, 0, $i,1,[2011])); it will consider only the month which have 1 and more days The calendar has 12 months with 30 or 31 days except February. So february is exception in this case. ( february have less than 30 days) The possible solution will be of using 1 as the 5th argument to initialize the month. you need to make a not of initializing the month to 1, since 1st is common to all the 12 months. you can use : date("M", mktime(0, 0, 0, $i,1,[2011])); year is optional it will take current year as default.