Oihana PHP Standards

isIso8601Date.php

Table of Contents

Functions

isIso8601Date()  : bool
Validates whether a string is a valid ISO 8601 calendar date.

Functions

isIso8601Date()

Validates whether a string is a valid ISO 8601 calendar date.

isIso8601Date(string $date[, bool $strict = false ]) : bool

Accepted formats:

  • Extended: YYYY-MM-DD (e.g. "2026-05-14")
  • Basic : YYYYMMDD (e.g. "20260514"), unless $strict is true

The function checks both the syntactic format and the calendar validity (i.e. February 30 is rejected, leap years are honored).

Parameters
$date : string

The date string to validate

$strict : bool = false

If true, only the extended format YYYY-MM-DD is accepted (default: false)

Tags
example
isIso8601Date('2026-05-14');         // true
isIso8601Date('20260514');           // true (basic)
isIso8601Date('20260514', true);     // false (strict rejects basic)
isIso8601Date('2026-02-30');         // false (invalid calendar date)
isIso8601Date('2024-02-29');         // true  (leap year)
isIso8601Date('2023-02-29');         // false (not a leap year)
isIso8601Date('2026-5-14');          // false (month not zero-padded)
link

ISO 8601 calendar dates

author

Marc Alcaraz (ekameleon)

since
1.0.2
Return values
bool

True if the string is a valid ISO 8601 date, false otherwise

On this page

Search results