PHP date()

StevenSwiniarski's avatar
Published May 23, 2022
Contribute to Docs

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

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours

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.

Code
Output

All contributors

Contribute to Docs

Learn PHP on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours