PHP date() Function
Example
Format a local date and time and return the formatted date strings:
<?php
// Prints the day
echo date("l") . "<br>";
// Prints the day, date, month, year, time, AM or PM
echo date("l jS \of F Y h:i:s A");
?>
Try it Yourself »
Definition and Usage
The date() function formats a local date and time, and returns the formatted date string.
Syntax
date(format, timestamp)
Parameter Values
| Parameter | Description |
|---|---|
| format | Required. Specifies the format of the outputted date string. The following characters can be used:
and the following predefined constants can also be used (available since PHP 5.1.0):
|
| timestamp | Optional. Specifies an integer Unix timestamp. Default is the current local time (time()) |
Technical Details
| Return Value: | Returns a formatted date string on success. FALSE on failure + an E_WARNING |
|---|---|
| PHP Version: | 4+ |
| Changelog: | PHP 8.0: timestamp is nullable now |
❮ PHP Date/Time Reference