Join David Powers for an in-depth discussion in this video What you should know before watching this course, part of PHP Date and Time Essential Training.
- This course focuses on working with dates and time in PHP, so you should already have a good handle on the basics of PHP. You should know how to write a script and how to use functions and control structures, such as conditional statements, loops and the ternary operator. Most of the code in this course uses PHP built-in classes, so you also need to have a basic understanding of working with objects. You don't need to be an expert, but you should know what I mean when I talk about using methods and properties.
In terms of physical requirements, all you need is a web server running PHP 5.4 or later. I'll be using a local testing server, but you can use a remote web server if you prefer. To follow the exercises, you'll also need a script editor. I'm using PHPStorm, version 8, but any script editor will do. There are several reasons for making PHP 5.4 the minimum version. The code in the examples uses the array shorthand syntax that was introduced in PHP 5.4.
Arrays are enclosed in square brackets instead of using the array keyword and parentheses. Some scripts also make use of array dereferencing to access an array element directly as the result of calling a function or method. Prior to PHP 5.4 you needed to store the array returned by the method or function and then access the individual array element. Now you can do it in a single operation like this. The other reason for making PHP 5.4 the minimum version is security.
Earlier versions of PHP are no longer officially supported. Each release branch of PHP is actively supported for only two years. After that it receives one year of security fixes before reaching its end of life. Ideally you should be using the latest version of PHP, which is 5.6 at the time this course is being recorded. A couple of videos in this course use the DateTimeImmutable class. This requires of minimum of PHP 5.5.
However I show a workaround that you can use with PHP 5.4. If the course sounds as though it might be beyond your current skills, there are plenty of other courses on Lynda.com that will get you up to speed. My introducing PHP lays the foundation of writing PHP scripts. If you're unsure about working with PHP objects, check out a quick primer on using PHP objects. It's part of the introduction to my course on accessing databases with object-oriented PHP.
It's probably all you need, but for the full story, Jon Peck has a great course called Object-Oriented Programming with PHP. And if you need a more detailed explanation of shorthand array syntax and array dereferencing, take a look at Understanding Array Improvements in Chapter Two of PHP 5.4 New Features with Drew Falkman.
- How PHP handles dates and time
- Setting the default time zone
- Displaying current date and time
- Getting a timestamp from text
- Using the DateTime class
- Getting and modifying a timestamp from DateTime
- Comparing DateTime objects
- Working with time zones
- Using DateInterval and DatePeriod
- Finding ISO week dates
- Calculating sunrise and sunset
Skill Level Intermediate
Q: How does calculating sunrise and sunset (as shown in chapter 7) work for locations north of the Arctic Circle?
A: In polar regions, date_sun_info() reports the value for sunrise and sunset as 1 on days when the sun never sets. The values are empty for days when the sun never rises.