Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

date_create

Creates a date object; returns `false` for an invalid string.

Syntax

date_create(string $datetime = "now", ?DateTimeZone $timezone = null): DateTime|false

Parameters

ParameterTypeDescription
$datetimestringOptional. The date as a string.
$timezone?DateTimeZoneOptional. The time zone.

Return value

DateTime|falseA `DateTime` object or `false`.

Examples

A valid and an invalid date:

<?php
 
var_dump(date_create('2026-03-15') !== false);
var_dump(date_create('not a date'));

Output:

bool(true)
bool(false)

Notes

Unlike new DateTime(), the function throws no exception — handy for validating input.

See also

  • DateTime — A mutable date and time object.
  • strtotime — Turns a textual date description into a timestamp.
  • checkdate — Checks whether such a date exists.

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.