The date_create Function
The date_create function creates an object
with a date, which can later be used to
perform certain operations. For example,
to add or subtract a time interval from the date using
date_modify
or to output the date in a different format using
the date_format function.
Syntax
date_create(?string $datetime = "now", ?DateTimeZone $timezone = null): DateTime|false
Example
Let's create an object with the date for the year 2025,
month 12, day 31:
<?php
$date = date_create('2025-12-31');
echo date_format($date, 'Y-m-d');
?>
Example
Let's create an object with the date for the year 2025,
month 12, day 31, then
add 1 day to it and output it in
the format 'day.month.year':
<?php
$date = date_create('2025-12-31');
date_modify($date, '1 day');
echo date_format($date, 'd.m.Y');
?>
Code execution result:
01.01.2026