date()

Published May 23, 2022
Contribute to Docs

The date() function creates a formatted date-time string from a local date-time.

Syntax

$datestring = date($format, $timestamp);

The $format string is a string specifying how the date/time is to be formatted. It uses the same syntax as the date_format() function.

The $timestamp parameter is a Unix timestamp, the date-time expressed as seconds elapsed from the Unix Epoch (Midnight GMT, January 1st, 1970). It is optional, and if omitted or NULL it defaults to the current local date and time.

Codebyte Example

The example below prints the current date and time using the date() function.

us
Visit us
code
Hide code
Code
Output
Hide output
Hide output
Loading...

All contributors

Looking to contribute?

Learn PHP on Codecademy