Creating A Simple Calendar in PHP

In this first of 4 tutorials, we build a simple, but working calendar for display purposes, looking at the techniques involved.

In this tutorial, we look at creating calendars in PHP. In this first of 4 tutorials, we build a simple, but working calendar for display purposes, looking at the techniques involved. In the second part we'll going to build a more advanced calendar that can display events for each day and has customised styling.

Advertisement DMXzone Calendar

 The DMXzone Calendar extension enables you to add a great looking calendar with many different styles and effects on your sites.  Enrich any form used for events, appointments or birthdays. Use it as a date picker or inline calendar with its unique design and in flight animation options. Embed multiple calendars, select date ranges, and limit the selection to specific dates.

Overview

Table of Content:

  • Creating Calendars in PHP
  • The PHP Date() Command
    • Overview
    • This returns the date in the format Sunday, 12th October 2003 for example
    • Useful tokens
  • Building the Calendar
    • Displaying the current month
      • Creating the HTML
      • Creating the PHP
      • Formatting Tip
      • The Calendar Output
  • Summary

Summary

In this article, we've looked at how to use the PHP date() command to retrieve useful information about the current date of a provided timestamp. We also looked at using the PHP mktime() command, to turn any date and / or time into a UNIX timestamp for use with the date() command.

Next we created the HTML structure for the calendar, which we then made dynamic using PHP to layout the calendar in the correct order. We also looked at formatting the HTML output so that it shows neatly in the browsers view source display,

Gareth Downes-Powell

Gareth Downes-PowellGareth has a range of skills, covering many computer and internet related subjects. He is proficient in many different languages including ASP and PHP, and is responsible for the setup and maintenance of both Windows and Linux servers on a daily basis.


In his daily web development work he uses the complete range of Macromedia software, including Dreamweaver MX, Flash MX, Fireworks MX and Director to build a number of websites and applications. Gareth has a close relationship with Macromedia, and as a member of Team Macromedia Dreamweaver, he has worked closely in the development of Dreamweaver, and was a beta tester for Dreamweaver MX.


On a daily basis he provides support for users in the Macromedia forums, answering questions and providing help on a range of different web related subjects. He has also written a number of free and commercial extensions for Dreamweaver MX, to further extend its capabilities using its native JavaScript API’s or C++.


As a web host, Gareth has worked with a range of different servers and operating systems, with the Linux OS as his personal favourite. Most of his development work is done using a combination of Linux, Apache and MySQL and he has written extensively about setting up this type of system, and also running Apache and MySQL under Windows.

See All Postings From Gareth Downes-Powell >>

Reviews

Revised Version ?

June 6, 2008 by John Ashton

Having used this great tutorial some years ago when it first appeared I was keen to learn about the revised version and the methods used to interact with a database. So, I purchased the Tut, downloaded then read it only to find that this is the same as I previously had.

So how do you intend to provide what was advertised, "Creating a simple calendar in PHP (updated) ???

Not happy guys !!

Advanced Calendars

October 5, 2018 by Martin Cotterill
"In the next part of this tutorial, we will look at styling the calendar using CSS, and making more advanced calendars that can interact with a database." Is this ready yet?

RE: Advanced Calendars

October 5, 2018 by Teodor Kuduschiev
Hello Martin, this article is more than 10 years old! Better check our newer articles and extensions.

You must me logged in to write a review.