PHP checkdate() Function Last Updated : 19 Sep, 2024 Comments Improve Suggest changes Like Article Like Report The checkdate() function in PHP is an important built-in function used to validate whether a given date is valid or not. It works by checking the values of month, day, and year, and returns true if the date is valid and false otherwise. This is particularly useful when you want to ensure a date is correct before performing operations with it. Syntax: checkdate ( $month, $day, $year )Parameters: The function accepts three mandatory parameters as shown above and described below: $month: Specifies the month (must be between 1 and 12).$day: Specifies the day (must be within the valid range for the given month and year).$year: Specifies the year (must be in the range 1 to 32767).Return Value:true: If the date is valid.false: If the date is invalid.Examples: Input : $month = 12 $day = 31 $year = 2017 Output : true Input : $month = 2 $day = 29 $year = 2016 Output : true Input : $month = 2 $day = 29 $year = 2017 Output : falseHow it Handles Leap Years:For February, in leap years (like 2016), checkdate() allows 29 days, while in non-leap years (like 2017), it only allows 28 days.Examples of checkdate() FunctionBelow programs illustrate the checkdate() function in PHP :Example 1: The program below check if the date is a valid one or not. php <?php // PHP program to demonstrate the checkdate() function $month = 12; $day = 31; $year = 2017; // returns a boolean value after validation of date var_dump(checkdate($month, $day, $year)); ?> Output: bool(true)Example 2: The program below check if the date is a valid one or not in case of a leap year and non-leap year. php <?php $month = 2; $day = 29; $year = 2016; var_dump(checkdate($month, $day, $year)); $month = 2; $day = 29; $year = 2017; var_dump(checkdate($month, $day, $year)); ?> Output: bool(true) bool(false)PHP is a server-side scripting language designed specifically for web development. You can learn PHP from the ground up by following this PHP Tutorial and PHP Examples. Comment More infoAdvertise with us Next Article PHP checkdate() Function C ChetnaAgarwal Follow Improve Article Tags : Misc Web Technologies PHP Practice Tags : Misc Similar Reads PHP date_sub() Function The date_sub() function is an inbuilt function in PHP that is used to subtract days, months, years, hours, minutes, and seconds from given date. This function returns a DateTime object on success and FALSE on failure. Syntax: date_sub($object, $interval)Parameters: The date_sub() function accepts tw 2 min read PHP | date_diff() Function The date_diff() is an inbuilt function in PHP which is used to calculate the difference between two dates. This function returns a DateInterval object on the success and returns FALSE on failure. Syntax: date_diff($datetime1, $datetime2); Parameters: The date_diff() function accepts two parameters a 2 min read PHP | filectime( ) Function The filectime() function in PHP is an inbuilt function which is used to return the last time the specified file was changed. The filectime() function returns the last time the file was changed as a Unix Timestamp on success and False on failure. The filectime() function checks for inode changes whic 2 min read PHP | fileatime( ) Function The fileatime() function in PHP is an inbuilt function which is used to return the last access time of a specified file. The fileatime() function returns the last access time of a file as a Unix Timestamp on success and False on failure. The filename is passed as a parameter to the fileatime() funct 2 min read PHP ereg() Function The Ereg() function in PHP searches a string to match the regular expression given in the pattern. The function is case-sensitive. This function has been deprecated in PHP 5.3.0 and removed in PHP 7.0.0. Syntax: int ereg ( string $pattern , string $str, array &$arr ); Parameters: pattern: It is 2 min read PHP | date_parse() Function The date_parse() is an inbuilt function in PHP which is used to find the detailed information about a specified date. This function returns an associative array of detailed information for a specified date on success and returns FALSE on failure Syntax: date_parse($date) Parameters Used: The date_pa 2 min read PHP | date_date_set() Function The date_date_set() function is an inbuilt function in PHP which is used to set a new Date. This function has four parameters $object, $year, $month and $day and returns DateTime object on success or false on failure. The date_date_set() function is an alias of DateTime::setDate() function. Syntax: 2 min read PHP | date_modify() Function The date_modify() function is an inbuilt function in PHP. Through the help of this function, we can modify or can alter the timestamp of DateTime object. The DateTime object and string modify are parameters in the calling function. Syntax: date_modify(DateTime $object, string $modify); Parameters: T 2 min read PHP | easter_date() Function The easter_date() function is a built-in function in PHP which returns the Easter date in the year passed as an argument. The current year is taken as default year when no arguments are passed as parameter. Syntax: easter_date( $year ) Parameter: The function accepts one optional parameter $year whi 2 min read PHP | easter_days() Function The easter_days() Function is a built-in function in PHP which returns the number of days after March 21, that the Easter Day is in the given year. When no year is given, the current year is taken as the default value. Syntax: easter_days( $year, $method ) Parameters: The function accepts two option 2 min read Like