Chapter 11. TIME, DATE, AND
CONFIGURATION FUNCTIONS
Time and Date...................................................................................................
Alternative Calendars.....................................................................................
ConfigurationChapter
The functions in this section fall into three categories: time and date, alternative
calendars, and configuration. The time and date functions are standard for any
programming language. They allow you to get the current date in several formats. The
calendar functions manipulate dates in various calendars, including ancient and obscure
calendars. The configuration functions offer a way to change the configuration of PHP on
a per-script basis.
Time and Date
All the time functions work off the UNIX epoch, which is January 1, 1970. Dates are
expressed as seconds since the epoch. This makes it easy to refer to dates with integers.
When a function calls for seconds since the epoch, I've referred to it as a timestamp.
boolean checkdate(integer month, integer day, integer year)
The checkdate function returns TRUE if a date is valid, FALSE otherwise. A day is
considered valid if the year is between 0 and 32,767, the month is between 1 and 12, and
lastly, if the day is within the allowable days for that month.
<?
if(checkdate(2,18,1970))
{
print("It is a good day");
}
?>
string date(string format, integer timestamp)
The date function returns a string describing the date of the timestamp according to the
format argument. Letters in the format argument are replaced with parts of the date or
time. Any characters not understood as codes are passed along in place. Format codes are
listed in Table 11.1.