checkdate()
checkdate() — Validate a Gregorian date.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
Checks the validity of the date formed by the arguments. A date is considered valid if each parameter is properly defined.
Signature
checkdate(int $month, int $day, int $year): bool
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $month | int | The month is between 1 and 12 inclusive. |
| $day | int | The day is within the allowed number of days for the given month. Leap years are taken into consideration. |
| $year | int | The year is between 1 and 32767 inclusive. |
Return value
Returns true if the date given is valid; otherwise returns false.
Example
A runnable snippet:
var_dump(checkdate(12, 31, 2000)); var_dump(checkdate(2, 29, 2001));
Output:
bool(true) bool(false)
See also
All PHP 8.5 built-in functions
Reference card built from the PHP manual page checkdate() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.