1. Computing

Simple PHP Calendar

By

1 of 5

Getting Calendar Variables
PHP calendars can be very useful. You can do things as simple as showing the date, and as complex as an online booking system. In this tutorial we will show you how to generate a very simple PHP calendar. Once you understand how to do this, you will be able to apply the same concepts to more complex calendars you may need.

 

 <?php 

//This gets today's date
$date =time () ;

//This puts the day, month, and year in seperate variables
$day = date('d', $date) ;
$month = date('m', $date) ;
$year = date('Y', $date) ;

//Here we generate the first day of the month
$first_day = mktime(0,0,0,$month, 1, $year) ;

//This gets us the month name
$title = date('F', $first_day) ;

In the first part of our code we are setting some variables we will need later in the script. First we find out what today's date is using the time () function. We then use the date () function to format our date appropriately for the $day, $month, and $year variables. Finally we use it to generate the name of the month, which will be the title of our calendar.

[See working calendar example]

Related Video
How to Create a PHP Calendar

©2014 About.com. All rights reserved.