PHP program to change date format

PHPServer Side ProgrammingProgramming

To change date format in PHP, the code is as follows−

Example

 Live Demo

<?php
   $date = "2019-11-11 05:25 PM";
   echo "Displaying date...\n";
   echo "Date = $date";
   echo "\nDisplaying updated date...\n";
   echo date('Y-m-d H:i', strtotime($date. ' + 20 days'));
?>

Output

This will produce the following output−

Displaying date...
Date = 2019-11-11 05:25 PM
Displaying updated date...
 2019-12-01 17:25

Example

Let us now see another example−

 Live Demo

<?php
   $date = date_create("2019-11-11");
   echo "Displaying date...\n";
   echo date_format($date,"Y/m/d H:i:s");
?>

Output

This will produce the following output−

Displaying date... 
2019/11/11 00:00:00
raja
Published on 26-Dec-2019 14:46:47
Advertisements