Is there a way to change the date format in php?


Yes, change the date format in PHP using the date() along with strtotime(). Let’s say the following is our date −

$dateValue = "2020-09-19";

Change the date format using the strtotime() method −

$modifiedDate= date("d-m-Y", strtotime($dateValue));  

Example

 Live Demo

<!DOCTYPE html>
<html>
<body>
<?php
   $dateValue = "2020-09-19";
   echo "The original date format is=",$dateValue,"<br>";
   $modifiedDate= date("d-m-Y", strtotime($dateValue));  
   echo "The changed date format is= ".$modifiedDate;  
?>
</body>
</html>

Output

This will produce the following output

The original date format is=2020-09-19
The changed date format is= 19-09-2020

Updated on: 13-Oct-2020

65 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements