The date_format Function
The date_format function outputs data
from a date object in a specific format.
The date must be an object created by
the date_create function.
The format control commands are the same
as in the date function.
Syntax
date_format(DateTimeInterface $object, string $format): string
Example
Let's create a date object 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'
See Also
-
the
date_modifyfunction,
which adds or subtracts time intervals from a date