note 77490 added to function.mktime
| From: | JonathanWoodard at osu1 dot php dot net | Date: | Fri, 31 Aug 2007 14:31:05 +0000 |
| Subject: | note 77490 added to function.mktime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-129943@lists.php.net to get a copy of this message | ||
NB: one 'gotcha' with the implementation of mktime()'s parameters:
<?php
for( $i = 1 ; $i <= 12 ; $i++ )
{
echo "Month '$i' is: " . date( "F" , mktime( 0 , 0 , 0 , $i ) ) .
"\n";
}
?>
Will output:
Month '1' is: January
Month '2' is: March
Month '3' is: March
Month '4' is: May
Month '5' is: May
Month '6' is: July
Month '7' is: July
Month '8' is: August
Month '9' is: October
Month '10' is: October
Month '11' is: December
Month '12' is: December
on the 31st day of every month.
Why? Because the 5th parameter "day" defaults to "right now," which will not
work reliably for days after the 28th.
To make sure this doesn't happen, specify the first day of the month:
<?php
mktime( 0 , 0 , 0 , $i , 1 )
?>
----
Server IP: 209.41.74.194
Probable Submitter: 141.211.170.67
----
Manual Page -- http://www.php.net/manual/en/function.mktime.php
Edit -- https://master.php.net/note/edit/77490
Del: integrated -- https://master.php.net/note/delete/77490/integrated
Del: useless -- https://master.php.net/note/delete/77490/useless
Del: bad code -- https://master.php.net/note/delete/77490/bad+code
Del: spam -- https://master.php.net/note/delete/77490/spam
Del: non-english -- https://master.php.net/note/delete/77490/non-english
Del: in docs -- https://master.php.net/note/delete/77490/in+docs
Del: other reasons-- https://master.php.net/note/delete/77490
Reject -- https://master.php.net/note/reject/77490
Search -- https://master.php.net/manage/user-notes.php