Home >>PHP Date Time Functions >PHP date_format() Function
PHP date_format() Function is used to format the given input date and time value. It return a new DateTime object value in the defined format. It accepts two parameter $object and $format.
Synatx:
date_format(object, format)
Parameter | Description |
---|---|
object | This is a required. This parameter defines a DateTime object returned by date_create(). |
format | This is a required. This parameter defines the format for the date. |
Here is an example of date_format() Function in PHP
<html> <body> <?php $date=date_create("2014-03-16"); echo date_format($date,"Y/m/d H:i:s"); ?> </body> </html>
Example 2
<html> <body> <?php $date=date_create("31-01-2020"); echo date_format($date,"d/m/y"); ?> </body> </html>