Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

date

Formats a date and time.

Syntax

date(string $format, ?int $timestamp = null): string

Parameters

ParameterTypeDescription
$formatstringThe format string: `d` is the day, `m` the month, `Y` the year, `H:i:s` the time.
$timestamp?intOptional. 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-30

Notes

Format letters are case-sensitive: m is the month, while M is its English abbreviation; minutes are i, not m.

See also

  • time — Returns the current timestamp.
  • strtotime — Turns a textual date description into a timestamp.
  • checkdate — Checks whether such a date exists.

Related recipes

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.

Thanks for reading!

Donate to the site — we work hard for you.