Creating Calendar in PHP


In this tutorial I will show you how to create a calendar script in PHP
on Tuesday 13 February 2007
by Administrator author list
in Tutorials
hits: 114422

In this tutorial I will show you how to create a calendar script in PHP. We will create a simple but good looking - easy customizable via CSS - calendar table.

[html] In this tutorial I will show you how to create a calendar script in PHP. We will create a simple but good looking - easy customizable via CSS - calendar table.

You can download a complete calendar script as well.

Step 1.
First of all try to collect the necessary information which are important to display the actual month and highlight the actual day. Besides this we want to display the actual month and year informations as well. To do this we need 3 special days informations:
  1. The actual day
  2. The first day of the actual month
  3. The last day of the actual month

With the above mentioned informations we can decide what day was the first day, how long is the month and of course which is the actual day.

Step 2.
To get the information mentioned in Step 1 we will use the PHP built in function: getdate(). Without parameters this function returns the actual day informations in an array as follows:
Array
(
[seconds] => 40
[minutes] => 58
[hours] => 21
[mday] => 17
[wday] => 2
[mon] => 6
[year] => 2003
[yday] => 167
[weekday] => Tuesday
[month] => June
[0] => 1055901520
)

To get the last day of the month with getdate we need to try to get the 0. day of the next month. So the code to get the information looks like this:
<?php
    $today    
getdate();
    
$firstDay getdate(mktime(0,0,0,$today['mon'],1,$today['year']));
    
$lastDay  getdate(mktime(0,0,0,$today['mon']+1,0,$today['year']));
?>




article index
page 1 - current : untitled page
page 2 : Part 2
page 3 : Part 3


Tags:

Render time: 0.5926 second(s); 0.4863 of that for queries. DB queries: 43.