date

PHP 4, PHP 5, PHP 7, PHP 8
date - Format a local time/date

date( string$format, [int|null$timestamp = null] ): string

Returns a string formatted according to the given format string using the given integer timestamp or the current time if no timestamp is given. In other words, timestamp is optional and defaults to the value of time.

Parameters

format

Format accepted by DateTimeInterface::format.

timestamp

The optional timestamp parameter is an int Unix timestamp that defaults to the current local time if timestamp is omitted or null. In other words, it defaults to the value of time.

Return Values

Returns a formatted date string. If a non-numeric value is used for timestamp, false is returned and an E_WARNING level error is emitted.

Exceptions and Errors

Every call to a date/time function will generate a E_WARNING if the time zone is not valid. See also date_default_timezone_set

Notes

Note:

To generate a timestamp from a string representation of the date, you may be able to use strtotime. Additionally, some databases have functions to convert their date formats into timestamps (such as MySQL's UNIX_TIMESTAMP function).

Timestamp of the start of the request is available in $_SERVER['REQUEST_TIME'].

Changelog

Version Description
8.0.0 timestamp is nullable now.

Related Functions

Example of date

Show all examples for date

PHP Version:


Function date:

Date and Time Functions

Most used PHP functions