How to Create a Calendar with PHP Code
Date Functions
One of the many interesting features of PHP are the date functions. These are of great help to anyone who wants to include a calendar on their website. Making a calendar is a relatively simple exercise, and is helped by the fact that PHP has the ability to represent days of the week in numbers. For this method Sunday is the first day – and is numbered as 0 – and Saturday the last and, of course, a number.
In order to make a calendar we need to know the present month and year, plus the day (or its corresponding number) that was the 1st of the month, and the day that will be the last. Those four, plus the number of days in the month, are the starting point.
Let’s have a look at the first sections of script:
Giving it a name
To start with, we name the calendar using the standard PHP scripts as follows:
The rules for creating rows and columns are as generally in php, and here’s how the script looks for the first two rows:
| -- | My Calendar | -- | ||||
| Su | Mo | Tu | We | Th | Fr | Sa |
| $j | ”;”; | |||||