string date_format ( DateTimeInterface $object , string $format )
$date = new DateTime('2022-05-12'); echo $date->format('M j, Y');
$date = new DateTime(); echo $date->format('Y-m-d H:i:s');Output: 2022-05-12 14:35:22 In this example, we create a new DateTime object with the current time. We then format the date as a string with the format 'Y-m-d H:i:s'. This format uses the full year, month, and day along with the 24-hour notation of hours, minutes, and seconds. This function is a built-in function in PHP and does not require any additional package library.