Calendar for the current month - with current day highlighted

Here is a code to create a calendar for the current month, with added CSS styling on current day etc.
[php]

table { border-collapse: collapse; text-align: center; vertical-align: center; font-family: Palatino Linotype; height: 300px; width: 500px; font-size: 13px; background: yellowgreen; } td.day{ padding: 5px; height: 30px; width: 30px; background: greenyellow; color: black; font-weight: bold; font-size: 20px; } td.date { height: 25px; width: 30px; font-size: 16px; } td.today { height: 25px; width: 30px; font-weight: bold; font-size: 16px; } h1 { font-size: 25px; font-family: Palatino Linotype; color: forestgreen; }

Calendar for <?php echo date("F, Y"); ?>

<?php $d = date("d"); $m = date("m"); $y = date("Y"); $day1 = date("w",mktime(0,0,0,$m,1,$y)); $daylast = date("w", mktime(0,0,0,$m,date("t"),$y)); $lastd = date("t"); $n = 1; while($n<=$lastd) { $w[$n] = date("w",mktime(0,0,0,$m,$n,$y)); if($w[$n]==0) { $w[$n]=7; } $n++; } ?> <?php foreach($w as $key=>$val) {
if($val!=7) {

 if($key === 1) {
  print "<tr>";
  $n = 1;
   $col = $val-1;
   print"<td colspan='$col' class = 'date'>&nbsp;</td>";
   
  if($key == $d) {
   print "<td class = 'today'>$key</td>";
  }else {
   print "<td  class = 'date'>$key</td>";
  }

 }else {
  if($key == $d) {
   print "<td class = 'today'>$key</td>";
  }else {
   print "<td  class = 'date'>$key</td>";
  }
 }
}else{
  if($key == $d) {
   print "<td class = 'today'>$key</td>";
  }else {
   print "<td  class = 'date'>$key</td>";
  }
 print "</tr>";
}
if($key == $lastd) {
 $col2 = 7-$daylast;
 print "<td colspan = '$col2' class = date>&nbsp;</td>";
}

}
?>

Mon Tue Wed Thu Fri Sat Sun
[/php]

Enjoy!

Sponsor our Newsletter | Privacy Policy | Terms of Service