PHP Function Reference

PHP checkdate() Function



The PHP checkdate() function is used to validate a Gregorian date formed by the arguments. A date is considered valid if each parameter is properly defined.

Syntax

checkdate(month, day, year)

Parameters

month Required. Specify the month as a number between 1 and 12 inclusive.
day Required. Specify the day as a number within the allowed number of days for the given month. Leap years are taken into consideration.
year Required. Specify the year as a number between 1 and 32767 inclusive.

Return Value

Returns true if the date given is valid, otherwise returns false.

Example:

The example below shows the usage of checkdate() function.

<?php
var_dump(checkdate(12, 31, 2000));
var_dump(checkdate(2, 29, 2004));
var_dump(checkdate(8, 31, 2000));

echo "\n";

var_dump(checkdate(2, 29, 2001));
var_dump(checkdate(12, 32, 2000));
var_dump(checkdate(13, 31, 2000));
?>

The output of the above code will be:

bool(true)
bool(true)
bool(true)

bool(false)
bool(false)
bool(false)

❮ PHP Date and Time Reference