Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

checkdate

Checks whether such a date exists.

Syntax

checkdate(int $month, int $day, int $year): bool

Parameters

ParameterTypeDescription
$monthintThe month, from 1 to 12.
$dayintThe day.
$yearintThe 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

  • date — Formats a date and time.
  • strtotime — Turns a textual date description into a timestamp.

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.

Thanks for reading!

Donate to the site — we work hard for you.