PHP checkdate() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Date/Time

Definition

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);
CallWhat 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

ParameterDescription
monthRequired. The month number. It must be between 1 and 12.
dayRequired. 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.
yearRequired. The year. It must be between 1 and 32767.

Return Value

Return ValueDescription
trueThe month, day and year form a valid date.
falseThe 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.

PHP
<?php
var_dump(checkdate(1, 15, 2024));
var_dump(checkdate(2, 30, 2024));
var_dump(checkdate(13, 1, 2024));
var_dump(checkdate(4, 31, 2024));

How It Works

  1. January 15, 2024 is a normal date, so the first call returns true.
  2. February never has 30 days, even in a leap year, so the second call returns false.
  3. There is no month number 13, so the third call returns false.
  4. April has only 30 days, so April 31 is invalid and the last call returns false.

Example 2 — Leap Years

February 29 only exists in leap years. checkdate() applies the full leap year rules for you.

PHP
<?php
$years = [1900, 2000, 2023, 2024];

foreach ($years as $year) {
    echo $year, ": ", checkdate(2, 29, $year) ? "valid" : "invalid", PHP_EOL;
}

How It Works

  1. The loop tests February 29 in four different years.
  2. 1900 is divisible by 100 but not by 400, so it is not a leap year.
  3. 2000 is divisible by 400, so it is a leap year and February 29 exists.
  4. 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;
    }
}

How It Works

  1. explode('-', $input) splits the string into year, month and day parts.
  2. Each part is cast with (int), because checkdate() expects integers.
  3. The arguments are passed in the order month, day, year.
  4. 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.

Next: date()

date() turns a Unix timestamp into a readable date and time string. If you do not pass a t.

date() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful