- Using Text Within date()
- Automatically Localizing Dates
- Manually Localizing Dates
- Using the Current Date the U.S./U.K./European Way
- Formatting a Specific Date
- Validating a Date
- Calculating a Relative Date
- Creating a Sortable Time Stamp
- Converting a String into a Date
- Determining Sunrise and Sunset
- Using Date and Time for Benchmarks
- Using Form Fields for Date Selection
- Create Self-updating Form Fields for Date Selection
- Calculating the Difference Between Two Dates
- Using GMT Date/Time Information
Formatting a Specific Date
echo ‘Time stamp: ‘ . mktime(12, 0, 0, 1, 1, 2001);
All previous phrases in this chapter have used the current date and time. However, it is also possible to use any other arbitrary date and time value. For this, the relevant functions (especially date() and strftime()) accept a second parameter—a time stamp of the date to be analyzed. This time stamp is an integer value, the date and time in the so-called epoche format. This is the number of seconds that passed since January 1st, 1970, midnight GMT—the beginning of the UNIX epoche. The time stamp/epoche value of the current moment can be retrieved using time() or by calling date(‘U‘) (see Table 3.1).
If you want to use another date, mktime() comes into play. This function converts a date provided by year, month, day, hour, minute, and second into an epoche value. Probably the strangest thing about this function is the order in which these parameters are passed:
You can also provide an optional seventh parameter, regardless of whether it is Daylight Savings Time (DST). This is relevant close to the change from or to DST because that does not happen at the same time over the world.
The preceding code calculates the time stamp for noon on the first day of this millennium. Because there was no year 0, this was January 1st, 2001.