PHP checkdate() Function

What is PHP checkdate() Function?

If you want to check whether a date is valid Gregorion date or not, use PHP checkdate() function.

Syntax:

checkdate(month, day, year)

Parameters:

The Function has 3 parameters which are all required-

month (Required): It specifies the month. It must be between 1 – 12 inclusive.

day (Required): It specifies the day. It must be between 1 – 31 inclusive. It must be a valid number of days based on the month and year (leap year).

year (Required): It specifies the year. It must be between 1 – 32767 inclusive.

The function returns-

Return Values:

The function returns-

  • TRUE – if the provided date is a valid Gregorian date.
  • FALSE – otherwise.

Examples:

Example:

<?php
echo "is 1/1/1 a valid Gregorian date? ";
echo checkdate(1, 1, 1) ? "Yes": "No";
echo "<br />";
echo "is 1/15/2026 a valid Gregorian date? ";
echo checkdate(1, 15, 2026) ? "Yes": "No";
echo "<br />";
echo "is 3/31/2029 a valid Gregorian date? ";
echo checkdate(9, 31, 2029) ? "Yes": "No";
?>

Output:

is 1/1/1 a valid Gregorian date? Yes
is 1/15/2026 a valid Gregorian date? Yes
is 3/31/2029 a valid Gregorian date? No

Notes on checkdate() Function:

  • The function can correctly identify the leap year
    <?php
    echo "is 2/29/2028 a valid leap year accordiong to Gregorian calendar? ";
    echo checkdate(2, 29, 2028) ? "Yes": "No";
    echo "<br />";
    echo "is 2/29/2030 a valid leap year accordiong to Gregorian calendar? ";
    echo checkdate(2, 29, 2030) ? "Yes": "No";
    ?>
    
  • Gregorian calendar is an internationally valid calendar that we follow in our daily life.

PHP Version Support:

PHP 4, PHP 5, PHP 7, PHP 8

Summary: PHP checkdate() Function

checkdate() is a PHP built-in date/time function. It is a quick method to find out validness of a date.

Reference:

https://www.php.net/manual/en/function.checkdate.php