In PHP, checkdate() checks whether a date made from a month, a day and a year really exists on the Gregorian calendar. It returns true for a real date and false for an impossible one.
You use checkdate() to validate dates before you save or process them. It knows how many days each month has and it handles leap years, so February 29 is valid in 2024 but not in 2023. Remember the argument order: month first, then day, then year.
Syntax
Call checkdate() with the values you need. Start with this line.
PHP
$isValid = checkdate(2, 29, 2024);
Call
What it does
checkdate(1, 15, 2024)
Returns true because January 15, 2024 is a real date.
checkdate(2, 30, 2024)
Returns false because February never has 30 days.
checkdate(2, 29, 2023)
Returns false because 2023 is not a leap year.
checkdate() only checks the three numbers. It does not read strings like '2024-01-15', so split the string first and cast each part to an int. The order is month, day, year, which is different from the Y-m-d order that many people expect.
Library declarations
PHP
checkdate(int $month, int $day, int $year): bool
Parameters
Parameter
Description
month
Required. The month number. It must be between 1 and 12.
day
Required. The day of the month. It must be between 1 and the number of days in that month, and leap years are taken into account.
year
Required. The year. It must be between 1 and 32767.
Return Value
Return Value
Description
true
The month, day and year form a valid date.
false
The date does not exist, or one of the values is out of range.
PHP Examples
Example 1 — Checking Simple Dates
Pass a month, a day and a year. checkdate() answers with true or false.
The loop tests February 29 in four different years.
1900 is divisible by 100 but not by 400, so it is not a leap year.
2000 is divisible by 400, so it is a leap year and February 29 exists.
2023 is not divisible by 4 and 2024 is, so only 2024 is valid.
Example 3 — Validating a Date String
checkdate() works with numbers, so split a Y-m-d string and cast each part to an integer before you check it.
PHP
<?php
$inputs = ['2024-01-15', '2024-02-30'];
foreach ($inputs as $input) {
[$year, $month, $day] = explode('-', $input);
if (checkdate((int) $month, (int) $day, (int) $year)) {
echo $input, " is valid", PHP_EOL;
} else {
echo $input, " is not valid", PHP_EOL;
}
}
Output
2024-01-15 is valid
2024-02-30 is not valid
How It Works
explode('-', $input) splits the string into year, month and day parts.
Each part is cast with (int), because checkdate() expects integers.
The arguments are passed in the order month, day, year.
January 15 passes the check, but February 30 fails and shows the error message.
Frequently Asked Questions
It checks whether a month, day and year make a real calendar date. It returns true if the date exists and false if it does not, for example February 30 or month 13.
The order is month, day, year. This surprises many beginners because strings like 2024-01-15 use year, month, day. Passing the values in the wrong order often gives false.
Yes. checkdate(2, 29, 2024) returns true because 2024 is a leap year, while checkdate(2, 29, 2023) returns false. Century years such as 1900 and 2000 follow the full leap year rules.
No. checkdate() needs three integers. Use explode() to split the string, cast each part with (int), and then call checkdate(). For flexible formats, use DateTimeImmutable::createFromFormat() and check for errors.
Creating a DateTime from an impossible date such as 2024-02-30 does not fail. PHP rolls it over to the next valid day. checkdate() tells you the date was invalid before any rollover happens.