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.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
How to Validate Gregorian Dates in PHP with checkdate()

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)
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

BackendTutorialcheckdatedate validation
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.