Sometimes we need to change the date format in PHP for example date is stored in a database YYYY-MM-DD format but when showing this date on the public web need to show DD-MM-YYYY so in this post I will teach you how to change the date format in PHP

<?php  
    $RegistrationDate = "2022-05-20";  
    //if you want date formate like ("DD-MM-YYYY")
    $NewRegistrationDate = date("d-m-Y", strtotime($RegistrationDate));  
    echo "New date format is: ".$NewRegistrationDate;
    echo "<br>";
    
    //if you want date formate like ("MM-DD-YYYY")
    $NewRegistrationDate = date("m-d-Y", strtotime($RegistrationDate));  
    echo "New date format is: ".$NewRegistrationDate;
         
?>  
Output :-
The new date format is: 20-05-2022
The new date format is: 05-20-2022