List Info

Thread: note 77490 added to function.mktime




note 77490 added to function.mktime
user name
2007-08-31 09:31:05
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  -- h
ttps://master.php.net/note/delete/77490/integrated
Del: useless     -- http
s://master.php.net/note/delete/77490/useless
Del: bad code    -- htt
ps://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     -- http
s://master.php.net/note/delete/77490/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/77490
Reject      -- https://mast
er.php.net/note/reject/77490
Search      -- https://
master.php.net/manage/user-notes.php

-- 
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php


[1]

about | contact  Other archives ( Real Estate discussion Medical topics )