eXorithm – Execute Algorithm: View / Run Algorithm calendar_month

Logo Beta

function calendar_month ($month$year
{
  $start = getdatemktime(0,0,0,$month,1,$year));
  $end = getdatemktime(0,0,0,$month+1,0,$year));
  
  $end_date = $end'mday'];
  $start_day = $start'wday'];
  
  $html = "<table border=1><tr>
  <th width=100>Sunday</th>
  <th width=100>Monday</th>
  <th width=100>Tuesday</th>
  <th width=100>Wednesday</th>
  <th width=100 >Thursday</th>
  <th width=100>Friday</th>
  <th width=100>Saturday</th>
  </tr>n"
  
  $date = 0;
  $week_day = 0;
  while ($date$end_date) {
    if ($week_day==0)
      $html .= "<tr>n"
    
    if ($date==0)
      if ($week_day==$start_day
        $date++;
    else
      $date++;
  
    if ($date==0)
      $html .= "<td></td>"
    else
      $html .= "<td height=85 valign=top>$date</td>"
    
    $week_day = ($week_day+1) % 7;
    
    if ($week_day==0)
      $html .= "</tr>n"
  }
  
  if ($week_day!=0) {
    $html .= str_repeat"<td></td>", 7-$week_day);
    $html .= "</tr>n"
  }
  
  $html .= "</table>"
  return $html