How to format a date
Short answer
date() takes a format and a timestamp. strtotime() turns a date string into a timestamp:
<?php
echo date('d.m.Y', strtotime('2025-03-15'));Output:
15.03.2025The DateTime class
A DateTime object is more convenient when you need to do more with the date: compare it, add days, change the time zone.
<?php
$date = new DateTime('2025-03-15 14:30');
echo $date->format('d.m.Y H:i');Output:
15.03.2025 14:30The main format characters
| Character | Meaning | Example |
|---|---|---|
d | Day with a leading zero | 05 |
m | Month with a leading zero | 03 |
Y | Four-digit year | 2025 |
H | Hours, 24-hour clock | 14 |
i | Minutes | 30 |
s | Seconds | 07 |
The current date
Without a second argument date() uses the current time:
<?php
echo date('Y-m-d');