PHP checkdate() function: Here, we will find out about the PHP checkdate() function with its syntax, parameters, returns type, and example.
PHP checkdate() function
checkdate() function is utilized to check the substantial Gregorian dates. It acknowledges the date and returns Boolean values (True/False) in light of the date values.
Syntax:
checkdate(month,day,year);
Parameter(s):
- month – It indicates the month in the numbers beginning from 1 to 12.
- day – It indicates the day in the numbers beginning from 1 to 31.
- year – It indicates the year in the numbers from 1 to 32767.
Return value:
- It returns “Genuine” – if the date is substantial, else it returns “FALSE“.
Example: PHP code to check whether the given date is the substantial Gregorian date
<?php
var_dump(checkdate(12, 31, 2019)); //valid
var_dump(checkdate(12, 31, -2018)); //invalid
var_dump(checkdate(2, 29, 2019)); //invalid
var_dump(checkdate(2, 29, 2020)); //valid
//checking through conditions
if (checkdate(12, 31, 2019)) echo "Valid\n";
else echo "Invalid\n";
if (checkdate(12, 31, -2018)) echo "Valid\n";
else echo "Invalid\n";
if (checkdate(2, 29, 2019)) echo "Valid\n";
else echo "Invalid\n";
if (checkdate(2, 29, 2020)) echo "Valid\n";
else echo "Invalid\n";
?>
Output
bool(true)
bool(false)
bool(false)
bool(true)
Valid
Invalid
Invalid
Valid
Reference: PHP checkdate() function