Important alert: (current site time 7/15/2013 8:44:12 PM EDT)
 

VB icon

Calendar Script

Email
Submitted on: 3/13/2003 6:07:10 AM
By: Randy McCleary 
Level: Beginner
User Rating: By 3 Users
Compatibility: 5.0 (all versions)
Views: 9032
(About the author)
 
     This is a simple Calendar Display script. It will display the current Month, with the current day marked. This can be placed on a webpage, anywhere you need to display it.

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
=**************************************
= Name: Calendar Script
= Description:This is a simple Calendar Display script. It will display the current Month, with the current day marked. This can be placed on a webpage, anywhere you need to display it.
= By: Randy McCleary
=
=This code is copyrighted and has= limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=422&lngWId=6=for details.=**************************************

#!/usr/bin/perl -w
###################################################
## This is a simple Calendar Display script.
## It will display the current Month, with the
## current day marked. This can be placed on a
## webpage, anywhere you need to display it.
###################################################
use POSIX;
use strict;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use Time::Local;
	
###################################################
## Define Globals
###################################################
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = 0;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
my $month_name = ("January", "February", "March", 
						"April", "May", "June", "July", 
						"August", "September", "October", 
						"November", "December")[$mon];
	
	
my $time_t = POSIX::mktime(0, 0, 1, 1, $mon, $year);
my @attribs = localtime($time_t);
my $start_day = @attribs[6] + 1;
my @month_days = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
my $days_in_month = @month_days[$mon];
	
&init();
&Display_Calendar();
###################################################
## Sub to Initiate the calendar
###################################################
sub init {
		print header;
		
		#########################
		## Check for leap year
		#########################
		if($mon == 1) {
			$year += 1900;
			if($year%4 == 0 && $year%100 == 0 && $year%400 == 0) {
				$days_in_month = 29;
			} 
			elsif($year%4 == 0 && $year%100 != 0) {
				$days_in_month = 29;
			}
		}		
		$days_in_month += $start_day - 1;
}
###################################################
## Sub to Diplay the generated Calendar Month
###################################################
sub Display_Calendar {
		
		###################################################
		## Begin to Print out the Calendar in a Table
		###################################################
		print "<table cellspacing=\"1\" cellpadding=\"2\" border=\"0\" bgcolor=\"#336699\">\n";
		print "	<tr>\n";
		print "		<th colspan=\"7\"><font color=\"#FFFFFF\">$month_name</font></th>\n";
		print "	</tr>\n";
		print "	<tr>\n";
		print "		<th width=\"20\" bgcolor=\"#CCCCCC\">S</th>\n";
		print "		<th width=\"20\" bgcolor=\"#CCCCCC\">M</th>\n";
		print "		<th width=\"20\" bgcolor=\"#CCCCCC\">T</th>\n";
		print "		<th width=\"20\" bgcolor=\"#CCCCCC\">W</th>\n";
		print "		<th width=\"20\" bgcolor=\"#CCCCCC\">T</th>\n";
		print "		<th width=\"20\" bgcolor=\"#CCCCCC\">F</th>\n";
		print "		<th width=\"20\" bgcolor=\"#CCCCCC\">S</th>\n";
		print "	</tr>\n";
		
		my $day = 1;
		my $count = 0;
		my $temp = 0;
		for(my $i=1; $i<=$days_in_month; $i++) {
			if($count == 0) { 
				print "		<tr>\n"; 
			}
			if($count % 7 == 0 && $count != 0) { 
				print "		</tr><tr>\n"; 
			}
			
			if($i < $start_day) {
				print "			<td bgcolor=\"#EFEFEF\" align=\"center\">-</td>\n";
			} 
			else {
				if($day == $mday) {
					print "			<td bgcolor=\"#FFFF00\" align=\"center\"><b>$day</b></td>\n";
				} 
				else {
					print "			<td bgcolor=\"#FFFFFF\" align=\"center\">$day</td>\n";
				}
				$day++;
			}
			
			if($i == $days_in_month && $count % 7 != 6 ) {
				$temp = 6 - $count % 7;
				for(my $j=1; $j <= $temp; $j++) {
					print "			<td bgcolor=\"#EFEFEF\" align=\"center\">-</td>\n";
				}
				print "		</tr></table>\n";
			}
			$count++;
		}
}
	
	
	
	
	
	


Other 28 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.