Page 1 of 1

Help with this date problem....

Posted: Sat Feb 26, 2005 7:12 am
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;

Posted: Sat Feb 26, 2005 7:27 am
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:

Posted: Sat Feb 26, 2005 7:31 am
by neophyte
I must have missed that in the manual.

Thanks