Oihana PHP Standards

isIso8601DateTime.php

Table of Contents

Functions

isIso8601DateTime()  : bool
Validates whether a string is a valid ISO 8601 date-time.

Functions

isIso8601DateTime()

Validates whether a string is a valid ISO 8601 date-time.

isIso8601DateTime(string $value[, bool $strict = false ]) : bool

Accepted shape:

  • Date : YYYY-MM-DD (extended)
  • Sep. : T (mandatory in strict mode, space allowed otherwise)
  • Time : HH:MM:SS, optionally with fractional seconds (.fff...)
  • Offset: optional Z, ±HH:MM or ±HHMM

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

Parameters
$value : string

The date-time string to validate

$strict : bool = false

If true, the T separator is mandatory (default: false)

Tags
example
isIso8601DateTime('2026-05-14T08:15:30Z');         // true
isIso8601DateTime('2026-05-14T08:15:30+02:00');    // true
isIso8601DateTime('2026-05-14T08:15:30.123Z');     // true (milliseconds)
isIso8601DateTime('2026-05-14 08:15:30');          // true (space separator)
isIso8601DateTime('2026-05-14 08:15:30', true);    // false (strict requires T)
isIso8601DateTime('2026-02-30T00:00:00Z');         // false (invalid calendar date)
isIso8601DateTime('2026-05-14T24:00:00');          // false (invalid hour)
link

ISO 8601 combined representations

author

Marc Alcaraz (ekameleon)

since
1.0.2
Return values
bool

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

On this page

Search results