PHP date_format() Function
Example
Return a new DateTime object, and then format the date:
<?php
$date=date_create("2013-03-15");
echo date_format($date,"Y/m/d H:i:s");
?>
Try it Yourself »
Definition and Usage
The date_format() function returns a date formatted according to the specified format.
Note: This function does not use locales (all output is in English).
Tip: Also look at the date() function, which formats a local date/time.
Syntax
date_format(object, format)
Parameter Values
| Parameter | Description |
|---|---|
| object | Required. Specifies a DateTime object returned by date_create() |
| format | Required. Specifies the format for the date. The following characters can be used:
and the following predefined constants can also be used (available since PHP 5.1.0):
|
Technical Details
| Return Value: | Returns the formatted date as a string. FALSE on failure |
|---|---|
| PHP Version: | 5.2+ |
❮ PHP Date/Time Reference