Articles: 843 | Categories: 148   
   
   
Home Articles Contact Us
 
 
 
 
Datemenu (0 Comments)
Admin: Posted Date: April 4, 2010

Datemenu is an interactive PHP created calendar for your website. Features capabilities to handle text months and days. It can also display the appropiate suffix on a day.

PHP: Web Calendar With Events

 

This coding example builds a calendar for the current month. It provides navigation to go backward or forward, month-by-month. Click a date to fill in a form to add an event.

Use the calendar with or without the "add event" feature. Building a calendar on-the-fly without other bells and whistles has its practical uses.

Building the Calendar for the Current Month
First generate the calendar for the current month. Grab today's date. Then get the month and year. Create a new date of the first of the month. From this date you can figure out which day of the week it falls on.

Next, figure out the last day of the month. I loop through the days 28th - 32nd and create a new date out of it. Compare the current month to this new date's month. If it changed, the previous day was the last day of the month.

You then start on the first day, postitioning yourself over however many weekdays the first is in. Next, loop through all the days until the day reaches the end of the month. Keep track of the weekdays using modulus 7 to find the end of each week.

More Info About Calendars
PHP has some great date function capabilities such as built-in support for text months and days. Plus, it can even display the appropiate suffix on a day. ('st', 'nd' 'rd', 'th' in 1st, 2nd, 3rd 4th). View the source code and the PHP documentation to see how these functions are used.

I wrote a similar calendar in ASP. You can download the JScript ASP source code for that calendar below. Note it is different than the PHP version shown here.

 

 

 

 
 
Add a Comment:
 
(You must be signed in to comment on an article. Not a member? Click here to register)
   
Title:

Comments: