PHP | DateTime format() Function Last Updated : 10 Oct, 2019 Comments Improve Suggest changes Like Article Like Report The DateTime::format() function is an inbuilt function in PHP which is used to return the new formatted date according to the specified format. Syntax: Object oriented style string DateTime::format( string $format ) or string DateTimeImmutable::format( string $format ) or string DateTimeInterface::format( string $format ) Procedural style string date_format( DateTimeInterface $object, string $format ) Parameters: This function uses two parameters as mentioned above and described below: $object: This parameter holds the DateTime object. $format: This parameter holds the format accepted by date() function. Return Value: This function return the new formatted date string on success or False on failure. Below programs illustrate the DateTime::format() function in PHP: Program 1: php <?php // Initialising the DateTime() object with a date $datetime = new DateTime('2019-09-30'); // Calling the format() function with a // specified format 'd-m-Y' echo $datetime->format('d-m-Y'); ?> Output: 30-09-2019 Program 2: php <?php // Initialising the DateTime() object with a date $datetime = new DateTime('2019-09-30'); // Calling the format() function with a // specified format 'd-m-Y H:i:s' echo $datetime->format('d-m-Y H:i:s'); ?> Output: 30-09-2019 00:00:00 Reference: https://www.php.net/manual/en/datetime.format.php Create Quiz Comment K Kanchan_Ray Follow 0 Improve K Kanchan_Ray Follow 0 Improve Article Tags : Web Technologies PHP PHP-date-time PHP-function Explore BasicsPHP Syntax4 min readPHP Variables5 min readPHP | Functions6 min readPHP Loops4 min readArrayPHP Arrays5 min readPHP Associative Arrays4 min readMultidimensional arrays in PHP5 min readSorting Arrays in PHP4 min readOOPs & InterfacesPHP Classes2 min readPHP | Constructors and Destructors5 min readPHP Access Modifiers4 min readMultiple Inheritance in PHP4 min readMySQL DatabasePHP | MySQL Database Introduction4 min readPHP Database connection2 min readPHP | MySQL ( Creating Database )3 min readPHP | MySQL ( Creating Table )3 min readPHP AdvancePHP Superglobals6 min readPHP | Regular Expressions12 min readPHP Form Handling4 min readPHP File Handling4 min readPHP | Uploading File3 min readPHP Cookies9 min readPHP | Sessions7 min read Like