maxudaskin Posted April 6, 2008 Share Posted April 6, 2008 <?php $year = 2007; while($year < 2020){ $year ++; $month = 0; while($month <= 12){ $month ++; $i = 1; $num = cal_days_in_month(CAL_GREGORIAN, $month, $year); while($i < $num){ echo $month . "-" . $year . " " . $i . "<br />"; $i ++; } } } ?> Output: http://www.virtualzoom.net/Untitled-1.php It gives an error for the 31st of December... Warning: cal_days_in_month() [function.cal-days-in-month]: invalid date. in /home/.grable/vzoom/virtualzoom.net/Untitled-1.php on line 9 Quote Link to comment https://forums.phpfreaks.com/topic/99792-cal_days_in_month-error/ Share on other sites More sharing options...
Barand Posted April 6, 2008 Share Posted April 6, 2008 echo date('t', strtotime('2008-02-01)); // 29 <?php for ($y=2008; $y<=2020; $y++) { for ($m=1; $m<=12; $m++) { $num = date('t', strtotime("$y-$m-01")); for ($d=1; $d<=$num; $d++) { printf('%4d-%02d-%02d<br/>', $y, $m, $d); } echo '<br>'; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/99792-cal_days_in_month-error/#findComment-510372 Share on other sites More sharing options...
maxudaskin Posted April 6, 2008 Author Share Posted April 6, 2008 How does that work? Quote Link to comment https://forums.phpfreaks.com/topic/99792-cal_days_in_month-error/#findComment-510591 Share on other sites More sharing options...
Barand Posted April 6, 2008 Share Posted April 6, 2008 date ('t', X) returns then number of the days in the month, where X is a timestamp value of a date in that month. www.php.net/date Quote Link to comment https://forums.phpfreaks.com/topic/99792-cal_days_in_month-error/#findComment-510674 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.