Home >>PHP Date Time Functions >PHP checkdate() Function

PHP checkdate() Function

PHP checkdate() Function

PHP checkdate() function is used to check the validity of the date passed in the arguments. It accepts the date in the format of mm/dd/yyyy. It returns a boolean value which is true if the date is a valid one, else it returns false.

Syntax:

  checkdate( $month, $day, $year );

Parameter Values

Parameter Description
month This is a required parameter. This parameter defines month as a number between 1 to 12.
day This is a required parameter. This parameter defines the day as a number between 1 to 31.
year This is a required parameter. This parameter defines the year as a number between 1 to 32767.

Here is an example of checkdate() function in PHP:

<html>
<body>

<?php

var_dump(checkdate(31,01,2020));  // wrong format
echo "<br>";
var_dump(checkdate(10,06,1999)); // right format

?>

</body>
</html>
Output:
bool(false)
bool(true)

Here is another example of checkdate() function in PHP:

<html>
<body>

<?php

var_dump(checkdate(12,32,2010));  // invalid day value
echo "<br>";
var_dump(checkdate(12,31,2020));  // valid values
echo "<br>";

?>

</body>
</html>
Output:
bool(false)
bool(true)

No Sidebar ads