In this article, you will learn how to format a date in PHP. The date_format() function returns a date formatted according to the specified format.
What is the syntax of the date_format() function in PHP?
date_format(object, format)
Parameter | Description |
---|---|
object | The DateTime object to return – Required |
format | The format to return the DateTime object in – Required |
Following are the possible characters that can be used to set the format of the date – in the format parameter of the function
Also, the following predefined constants can also be used.
Examples of the date_format() function
Example 1. In the following example, we return a new DateTime object according to the specified format.
<?php
$d=date_create("1998-01-14");
echo date_format($d,"Y/m/d H:i:s");
?>