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

PHPServer Side ProgrammingProgramming

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
raja
Published on 13-Oct-2020 10:13:03
Advertisements