Skip to main content
  • Home
  • Tags
OpenView360
Think Smart, Be Free, Choose Open Source
Home

calendar

Simple PHP Calendar

In:
  • calendar
  • coding
  • php
12Nov2009

I was searching today for a pre-made script for a simple php calendar and after a bit of search I've found this.

The code is a bit old, and the author's website doesn't seem to work anymore, so I decided to clean it up a bit.
You can see the result below.

  1. <?php
  2. // This gets today's date
  3. $date = time ();
  4.  
  5. // This puts the day, month, and year in seperate variables
  6. $day  = date('d', $date);
  7. $month= date('m', $date);
  8. $year = date('Y', $date);
  9.  
  10. // Here we generate the first day of the month
  11. $first_day = mktime(0,0,0,$month, 1, $year);
  12.  
  13. //This gets us the month name
  14. $title = date('F', $first_day);
  15.  
  16. //Here we find out what day of the week the first day of the month falls on
  17. $day_of_week = date('D', $first_day);
  18.  
  19. //Once we know what day of the week it falls on, we know how many blank days occure before it. If the first day of the week is a Sunday then it would be zero
  20. switch($day_of_week) {
  21.   case "Sun": $blank = 0; break;
  22.   case "Mon": $blank = 1; break;
  23.   case "Tue": $blank = 2; break;
  24.   case "Wed": $blank = 3; break;
  25.   case "Thu": $blank = 4; break;
  26.   case "Fri": $blank = 5; break;
  27.   case "Sat": $blank = 6; break;
  28. }
  29.  
  30. // We then determine how many days are in the current month
  31. $days_in_month = cal_days_in_month(0, $month, $year);
  32. ?>
  33.  
  34. <table cellpadding="0" cellspacing="0">
  35.   <tr>
  36.     <th colspan="7"><?php print $month; ?> <?php print $year; ?></th>
  37.   </tr>
  38.   <tr>
  39.     <td>Sun</td>
  40.     <td>Mon</td>
  41.     <td>Tue</td>
  42.     <td>Wed</td>
  43.     <td>Thu</td>
  44.     <td>Fri</td>
  45.     <td>Sat</td>
  46.   </tr>
  47.    <?php $day_count = 1;// This counts the days in the week, up to 7 ?>
  48.   <tr>
  49.   <?php while ($blank > 0): //first we take care of those blank days ?>
  50.     <td>&nbsp;</td> <?php $blank = $blank-1; $day_count++; ?>
  51.   <?php endwhile; ?>
  52.   <?php $day_num = 1; //sets the first day of the month to 1 ?>  
  53.  
  54.   <?php while ($day_num <= $days_in_month): //count up the days, until we've done all of them in the month ?>
  55.     <td><?php print $day_num; ?></td>
  56.     <?php $day_num++; $day_count++; ?>
  57.     <?php if ($day_count > 7): //Make sure we start a new row every week ?>
  58.   </tr>
  59.   <tr>
  60.     <?php $day_count = 1; ?>
  61.     <?php endif; ?>
  62.   <?php endwhile; ?>
  63.    
  64.   <?php while ($day_count >1 && $day_count <=7): //Finaly we finish out the table with some blank details if needed ?>
  65.     <td>&nbsp;</td>
  66.     <?php $day_count++; ?>
  67.   <?php endwhile; ?>
  68.   </tr>
  69. </table>

  • CoolGoose's blog
  • Add new comment
Entries (RSS)

About

Just your average goose.

Activity Stream

  • Thu, 11/03/2010 - 23:54

  • Digg CoolGoose dugg Google's Own Stated List of Competitors Grows from 2 to 10 11:54pm#
  • Digg CoolGoose dugg Mozilla Wants You To Help Rewrite Its Public License 11:54pm#
  • Digg CoolGoose dugg Commercial Gaming, Coming Soon to Linux? 11:54pm#
  • Digg CoolGoose dugg Why (I think) Ubuntu is Better Than Windows 11:29pm#
  • Digg CoolGoose dugg Android Crushes the Competition, iPhone Stands Still 11:28pm#
  • Digg CoolGoose dugg The Reasons Why Your Boss is Always Right 10:48pm#
  • Digg CoolGoose dugg CNET: Android phones get Opera Mini 5 beta 10:34pm#
  • Digg CoolGoose dugg 10 ways you might be breaking the law with your computer 10:12pm#

Tags in Tags

boris akunin carti css demon design devils digg erast fandorin gand general gnome iubire joey goebel kde linux love melancolie open source party php plugins poem power user problem protest quest random random thoughts regex regina noptii remorse renastere site tristete ubuntu windows
more tags

Search

Community

belletristisch.com - Online Literature
OS Revolution - Living in a matrix
At-byte.com - Stay Sharp
Linux PHP IDE

Who's online

There are currently 0 users and 2 guests online.

Syndicate

Syndicate content
Copyright alexandrubucur.com

Drupal port by 3rdWorld : Created by Design Disease