1. Home
  2. Computing & Technology
  3. PHP / MySQL

Simple PHP Calendar

By , About.com Guide

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]

Explore PHP / MySQL
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. Step By Steps
  5. PHP Calendar - Simple PHP Calendar - PHP Calendar Tutorial

©2009 About.com, a part of The New York Times Company.

All rights reserved.