Validating a Date

checkdate(2, 29, 2000)

When you get a datefor example, from the user using an HTML formthis data must be validated. This includes checking whether the month exists and if the month has enough days. If it's February, you might also want to find out whether it is a leap year.

checkdate function syntax

bool checkdate ( int $month , int $day , int $year )

This function validate a Gregorian date and accepts three parameters:

  1. Month between 1 and 12

  2. Day within the allowed number of days for the given month

  3. Year between 1 and 32767

checkdate returns TRUE if the date given is valid; otherwise returns FALSE.

Validating Date Information

  echo '2000 was ' .
    (checkdate(2, 29, 2000) ? 'a' : 'no') .
    ' leap year.<br />';
  echo '2100 will be ' .
    (checkdate(2, 29, 2100) ? 'a' : 'no') .
    ' leap year.';

But PHP would not be PHP if you really had to do this on your own. The function checkdate() validates a date; you provide the month, the day, and the year as parameters.