I l@ve RuBoard Previous Section Next Section

checkdate

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

month

Number of month

day

Number of day

year

Number of year

Checks a date for numeric validity.

Returns:

TRUE on success; FALSE on failure

Description:

Checks whether the given arguments form a valid date. The function allows for months of differing lengths and for leap years. A useful function for checking and validating form input in which a date is required. The allowed range for the year values is 0 to 32767 (inclusive).

Note that you can use mktime() to correct out-of-range dates, if appropriate.

Version:

PHP 3, PHP 4

See also:

getdate() 
mkdate() 
date() 
mktime() 

Example:

Check a date for validity
/* Expected output: 
 * 
 * Incorrect date; perhaps you meant March 1, 2001? */ 
$month = 15; 
$day = 1; 
$year = 2000; 
if (!$date = checkdate($month, $day, $year)) {
    $fixed_time = date('F j, Y', mktime(0, 0, 0, $month, $day, $year)); 
    print("Incorrect date; perhaps you meant $fixed_time?"); 
} else {
print("Date is OK."); 
} 
    I l@ve RuBoard Previous Section Next Section