Reputation: 28883
Here is a basic proof-of-concept script:
<?php
for($i = 1; $i < 13; $i++)
{
echo 'Using ' . $i . ' | ';
echo date('F', mktime(0,0,0,$i)) . " | ";
echo date('F', strtotime('2011-' . $i . '-01')) . "<br />";
}
And the output I get is:
Using 1 | January | January
Using 2 | March | February
Using 3 | March | March
Using 4 | April | April
Using 5 | May | May
Using 6 | June | June
Using 7 | July | July
Using 8 | August | August
Using 9 | September | September
Using 10 | October | October
Using 11 | November | November
Using 12 | December | December
This is killing me as it just stopped showing February and started showing March.
Upvotes: 2
Views: 140
Reputation: 22783
Arguments may be left out in order from right to left; any arguments thus omitted will be set to the current value according to the local date and time.
Thus, it sets the fifth argument to the current day (30 here). Which means it adds to the date, since 30 is an invalid day in February, and makes it march.
Upvotes: 1
Reputation: 2158
See this: http://www.php.net/manual/en/function.mktime.php#77490
Upvotes: 0
Reputation: 5203
Quite simple - you're running this on the 29th, 30th, or 31st of the month. mktime(0,0,0,2)
is really mktime(0,0,0,2,date('j'),date('Y'))
, which in the case of today would try to create February 30th 2011, which is March 2nd.
Upvotes: 3
Reputation: 449395
You are using mktime()
incorrectly.
int mktime ([ int $hour = date("H")
[, int $minute = date("i")
[, int $second = date("s")
[, int $month = date("n")
[, int $day = date("j") <------------ here
[, int $year = date("Y") <------------ and here
[, int $is_dst = -1 ]]]]]]] )
If you don't specify $day
and $year
, they will default to today's date.
Today is the 30th, which doesn't exist in February.
This will work:
echo date('F', mktime(0,0,0,$i,1,2011)) . " | ";
Upvotes: 10