Help with this date problem....

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Help with this date problem....

Post by neophyte »

Code: Select all

$current_year = intval(date('Y', time()));
$mon_options = '<option value="">Month</option>';
$year_options = '<option value="">Year</option>';
//Make the year_array

for ($x = 0; $x < 10; $x++)
&#123;
	$Y = date('Y', mktime(0,0,0,0,0, $current_year, 0));
	$y = date('y', mktime(0,0,0,0,0, $current_year, 0));
	$year_array&#1111;$y] = $Y;
	$current_year++;
&#125;
var_dump($year_array);
Why is the first year in year_array 2004?

outputs

Code: Select all

array(10) &#123;
  &#1111;"04"]=>
  string(4) "2004"
  &#1111;"05"]=>
  string(4) "2005"
  &#1111;"06"]=>
  string(4) "2006"
  &#1111;"07"]=>
  string(4) "2007"
  &#1111;"08"]=>
  string(4) "2008"
  &#1111;"09"]=>
  string(4) "2009"
  &#1111;10]=>
  string(4) "2010"
  &#1111;11]=>
  string(4) "2011"
  &#1111;12]=>
  string(4) "2012"
  &#1111;13]=>
  string(4) "2013"
&#125;
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

Might want reading Manual
mktime() wrote:The last day of any given month can be expressed as the "0" day of the next month
So that explains you getting 2004 instead of 2005.
because mktime returns 30th November, 2004.
Print out full date and see for yourself :wink:
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

I must have missed that in the manual.

Thanks
Post Reply