How to Convert date format yyyy-mm-dd => dd-mm-yyyy in PHP

Convert date from YYYY-MM-DD to DD-MM-YYYY (and from DD-MM-YYYY to YYYY-MM-DD).

The timestamp which is used as a base for the calculation of relative dates.

Use strtotime() and date()

Code

$Date = "2018-01-25";
$newDate = date("d-m-Y", strtotime($Date));
echo "New date format is: ". $newDate. " (YYYY-MM-DD)";

To convert the date-time format in php we can use strtotime() and date() function. using this function we can change the date format from one format to another.

Leave a Reply

Your email address will not be published. Required fields are marked *