date_create
Creates a date object; returns `false` for an invalid string.
Syntax
date_create(string $datetime = "now", ?DateTimeZone $timezone = null): DateTime|falseParameters
| Parameter | Type | Description |
|---|---|---|
| $datetime | string | Optional. The date as a string. |
| $timezone | ?DateTimeZone | Optional. 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
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.