checkdate
Checks whether such a date exists.
Syntax
checkdate(int $month, int $day, int $year): boolParameters
| Parameter | Type | Description |
|---|---|---|
| $month | int | The month, from 1 to 12. |
| $day | int | The day. |
| $year | int | The year. |
Return value
bool`true` if the date exists in the calendar.
Examples
A regular date and 30 February:
<?php
var_dump(checkdate(1, 30, 2025));
var_dump(checkdate(2, 30, 2025));Output:
bool(true)
bool(false)A leap year:
<?php
var_dump(checkdate(2, 29, 2024));
var_dump(checkdate(2, 29, 2025));Output:
bool(true)
bool(false)Notes
The argument order is American: the month first, then the day.
See also
Related recipes
In the tutorial
- Date and time — Working with dates in PHP — the date function, the DateTimeImmutable class, formats, adding to dates and the difference between them.