date
Formats a date and time.
Syntax
date(string $format, ?int $timestamp = null): stringParameters
| Parameter | Type | Description |
|---|---|---|
| $format | string | The format string: `d` is the day, `m` the month, `Y` the year, `H:i:s` the time. |
| $timestamp | ?int | Optional. A timestamp; the current moment by default. |
Return value
stringThe date in the given format.
Examples
The current date — depends on the day you run it:
<?php
echo date('d.m.Y');A date from a timestamp:
<?php
$timestamp = mktime(14, 5, 0, 1, 30, 2025);
echo date('d.m.Y H:i', $timestamp), "\n";
echo date('Y-m-d', $timestamp);Output:
30.01.2025 14:05
2025-01-30Notes
Format letters are case-sensitive: m is the month, while M is its English abbreviation; minutes are i, not m.
See also
Related recipes
- How to add days to a date
- How to check whether a date is a weekend
- How to check whether a year is a leap year
- How to convert a time to another time zone
- How to convert a timestamp to a date and back
- How to get the current date and time
- How to get the day of the week
- How to get the first and last day of a month
- How to write a message to a log file
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.