Here’s a simple, useful calendar script. This is a great way to check on days of the week for birthdays, holidays and other important occasions. You can also use it in conjunction with a data file (e.g. .csv, .xml) or database table (e.g. MySQL) as a tool to track appointments and special events.
This particular script makes many uses of the PHP date formatting functions. For more information on how PHP date formating works, see the PHP manual (http://us3.php.net/date).
First off, check to see if the user has sent previous values for the month and year via the form or the query string.
If this is the initial load of the form, then the system will pull the current month and year.
The “isset” function checks for the existence of the $_GET (query string) variables.
[php]
<!–//if values are not set for $Month and $Year, get current date values
if ((!isset($_GET[“Month”])) && (!isset($_GET[“Year”]))) {
$Month = date(“m”);
$Year = date(“Y”);
}
else{
$Month = $_GET[“Month”];
$Year = $_GET[“Year”];
}
[/php]
Now, we use the month and year values to get the Unix timestamp:
[php]
//Get viewed month
$Timestamp = mktime(0,0,0,$Month,1,$Year);
[/php]
We can use the date formatting function to get the full month name (e.g. January, February, etc.):
[php]
$MonthName = date(“F”, $Timestamp);
[/php]
We use the “echo” function to print the start of the table to the screen:
[php]
//Make calendar table
echo(“Calendar Table for $MonthName, $Year
“);
echo(
$value | |
$StartDate |
“);
[/php]
That takes care of the current month. Now what do we do if we want to see another month?
Here’s how we create a form that allows a user to select a different month:
[php]
//create select form
echo(”
[/php]
Again, this is a simple yet functional calendar script. If you’d like to see how to add other features to this calendar, such as flat file or database support, please let us know.