How to Convert date format yyyy-mm-dd => dd-mm-yyyy using 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 = "2021-01-25";
$newDate = date("d-m-Y", strtotime($Date));

Leave a Reply

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