Simple & Free Website Calendar


Visitors: 680

Offering a calendar to your site is a popular and easy addition to any site. In this article I will explain the relatively simple logic to allow you to create your own calendar. To be more specific, we'll create a calendar which shows either a monthly or weekly view and assume you can pass variables into the program.

The first thing needed are the minimum variables or parameters necessary to give ourselves a fair amount of flexibility. These variables will be the starting day, number of days to show, and any offset needed. The first two variables are pretty obvious, but the purpose of offset may not be clear. offset can be used to show previous and next calendars while maintaining view (e. g. monthly or weekly).

Next, considering that we would like to be able to show periods such as “this week", “this month", “next week", etc. we will need to create some logic to handle these options. To do this, we'll have 3 variables the program will accept: calendar, showdays, & offset. calendar will be used to request a specific calendar (e. g. “this week") while the other two variables come from those defined above. Our script will need to take the calendar and offset variables to populate the starting day. Note: All code shown here is pseudo-code and will not work in any known language. For the example calendar script in PHP , please visit the author's site.

// First, establish the starting day and number of days to show.
// Express number of days using “month" for a monthly show because months vary in number of days.

IF calendar = “this month"
start_day = first of the month
num_days = “month"
ELSE IF calendar = “this week"
start_day = last Sunday
num_days = 7
. . . continue for all acceptable forms
start_day = default day
num_days = default number

// Now modify start_day by the appropriate offset and establish number of days (count_max) to
// show appropriate for the value of num_days
IF num_days = “month"
start_day = first of the month adjusted by offset number of months
count_max = number of days in the month
start_day = start_day adjusted by offset number of days
count_max = num_days

// Determine the day of the week start_day falls on
start_day_of_week = day of week for start_day, this should be a number from 0 to 6.

We have now collected all the information necessary to show the appropriate calendar. Moving on, we now need to generate our calendar. Our calendar should output the header information and the name of the month as a caption. Then all which remains is to output each row. Let's take a look at how that can be achieved:

column_position = start_day_of_week

IF column_position > 0
OUTPUT: empty TD cell spanning column_position+1 cells
INCREMENT: column_position

original_start_day = start_day

current_day = start_day

WHILE (current_day - start_day) < count_max)
IF (column_position MOD 7) = 0
OUTPUT: open TR tag
OUTPUT: TD cell with current_day in it
INCREMENT: column_position
INCREMENT: current_day
IF (column_position MOD 7) = 0
OUTPUT: close TR tag

This will output each of the rows, wrapping on Saturday, but will leave the last TR tag open, so be sure to close it and the table. Then, all you need to do is save your file and use the code, setting the appropriate variables, wherever you would like! Now, this is an extremely simple example and adding features such as navigation and event management are definite pluses. For a copy of this script with functioning code , please see the author's website.

Jeremy Miller - Webmaster of Script Reference - The *NEW* PHP Reference & Tutorial Site For Non-Programmers


Article Source:

Rate this Article: 
Option Trading - Calendar Spreads & Time Decay
Rated 4 / 5
based on 5 votes

Related Articles:

Calendar Dayhaps - Create a free online calendar

by: Jim Loon (January 31, 2015) 
(Internet and Businesses Online/Social Media)

Articles: A Free & Effective Way To Promote Your Website

by: R Birch (July 09, 2006) 
(Writing and Speaking/Writing Articles)

Part I : Getting Free Hits Using These Simple Tips & Tricks

by: Prashant Parikh (March 22, 2005) 
(Internet and Businesses Online/SEO)

10 Simple Ways to Pay Less & Get Free Upgrades for Any Hotel Room

by: Julie Summers (July 15, 2005) 
(Travel and Leisure)

A Fast And Simple Way To Get Free Website Traffic

by: Tracie Johansen (May 23, 2008) 
(Internet and Businesses Online/Traffic Building)

Simple Tips on How to Promote Your Website for Free

by: Scott Brooks (May 08, 2008) 
(Internet and Businesses Online/Traffic Building)

3 Simple and Free Ways To Drive More Traffic To Your Website!

by: Steve Shulenski (January 05, 2007) 

10 Time-Saving Calendar & Scheduling Tips

by: Eve Abbott (June 03, 2005) 
(Self Improvement/Time Management)

A Simple Calendar For Your Garden

by: Graeme Knights (March 09, 2012) 
(Home and Family/Gardening)

Option Trading - Calendar Spreads & Time Decay

by: David Rivera (April 12, 2007)