Jump to content

cal_days_in_month error


maxudaskin

Recommended Posts

<?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

Link to comment
https://forums.phpfreaks.com/topic/99792-cal_days_in_month-error/
Share on other sites

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>';
    }
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.