How to Validate Gregorian Dates in PHP with checkdate()
This guide explains how PHP's checkdate() function validates Gregorian dates by checking month, day, and year values, details each parameter's accepted range, describes the boolean return, and provides example code demonstrating both a valid and an invalid date check.
Function Overview
The checkdate() function verifies whether the supplied month, day, and year constitute a valid Gregorian calendar date. It returns true if the date is valid and false otherwise.
Parameters
month : integer from 1 to 12.
day : integer representing the day of the month; must be within the number of days for the given month, with leap years taken into account.
year : integer from 1 to 32767.
Return Value
Boolean true on success, false on failure.
Example Usage
<?php
var_dump(checkdate(12, 31, 2000)); // valid date
var_dump(checkdate(2, 29, 2001)); // invalid (2001 is not a leap year)
?>Sample Output
bool(true)
bool(false)Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
