Creating Calendars in PHP part 3
In this article in the series, we look at using the PHP mktime() command which allows us to create Unix timestamps for a particular date and time. By using the PHP explode() command we can split a time or date that's been entered by a user into its component parts for use with the mktime() function. We then look at the PHP strtotime() command which can perform date and time based addition and subtraction, so we can easily add or subtract a period of time to or from an existing date / time.
In the final section, we create a custom function readCalendarData() which accepts a month number and year, and searches the database to find all events on or between the start and end of the month and using SQL to turn the datetime field into a timestamp field to make it easier to work with, and to allow us to easily sort the records into order of date and time. We then modify our existing calendar code so that it checks to see if each day number exists in the array, and if it does to turn the day number into a hyperlink to allow the user to see all events on that particular day.
Please note that this article forms part of a chapter in the DMXzone e-book PHP Web Applications for Dreamweaver: Juicy Solutions for the Busy Developer.
Table of Content:
- PHP commands for working with Dates & Timestamps
- The PHP mktime() command
- Creating Timestamps to find all records on a certain day
- Breaking an entered Date or Time into its separate parts
- Using the PHP strtotime() command to add or subtract time periods to / from a Timestamp
- Using strtotime() without passing a timestamp
- Using strtotime() with a timestamp
- Expanding the Calendar Example - Making it Dynamic
- Creating the MySQL Table
- Adding some example data
- Reading in the data from the Database
- Testing the function
- Modifying the Calendar Code
- Example Output
Gareth 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.
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 >>
Be the first to write a review
You must me logged in to write a review.