PHP date_format() function

PHP date_diff() function
PHP date_get_last_errors() function

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)
ParameterDescription
objectThe DateTime object to return – Required
formatThe format to return the DateTime object in – Required
PHP date_fomat() method

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");
?>
PHP date_diff() function
PHP date_get_last_errors() function
en English
X
Scroll to Top