timezone configuration directive, which can be manipulated per usual via the standard
routes (see Chapter 2) or by using the date_default_timezone_set() function. See the PHP manual for
more information.
CHAPTER 1 2 ?– D ATE AND T IME 325
Validating Dates
Although most readers could distinctly recall learning the ???Thirty Days Hath September???
poem1 back in grade school, it??™s unlikely many of us could recite it, present company
included. Thankfully, the checkdate() function accomplishes the task of validating
dates quite nicely, returning TRUE if the supplied date is valid, and FALSE otherwise. Its
prototype follows:
Boolean checkdate(int month, int day, int year)
Let??™s consider an example:
echo "April 31, 2007: ".(checkdate(4, 31, 2007) ? 'Valid' : 'Invalid');
// Returns false, because April only has 30 days
echo "
";
echo "February 29, 2004: ".(checkdate(02, 29, 2004) ? 'Valid' : 'Invalid');
// Returns true, because 2004 is a leap year
echo "
";
echo "February 29, 2007: ".(checkdate(02, 29, 2007) ? 'Valid' : 'Invalid');
// Returns false, because 2007 is not a leap year
Executing this example produces the following output:
April 31, 2007: Invalid
February 29, 2004: Valid
February 29, 2007: Invalid
Formatting Dates and Times
The date() function returns a string representation of the current date and/or time
formatted according to the instructions specified by a predefined format.
Pages:
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403