convert mysql date to dd mm yyyy format in php – How to change date format in PHP?

convert mysql date to dd mm yyyy format in php. You can first use the PHP strtotime() function to convert any textual datetime into Unix timestamp.

Free Live Chat for Any Issue

convert mysql date to dd mm yyyy format in php

convert mysql date to dd mm yyyy format in php or php changr date format or convert dd/mm/yyyy to yyyy-mm-dd in mysql php Examples for Convert a date YYYY-MM-DD to DD-MM-YYYY in PHP.

Change YYYY-MM-DD to DD-MM-YYYY

<?php  
    $joinDt = "2022-09-15";  
    $endDt = date("d-m-Y", strtotime($joinDt));  
    echo "New date format is: ".$endDt. " (MM-DD-YYYY)";  
?>  

Change YYYY-MM-DD to MM-DD-YYYY

In the below example, i have date 2022-02-26 in YYYY-MM-DD format, and i will convert this to 02-26-2022 (MM-DD-YYYY) format.

<?php  
    $joinDt = "2022-02-26";  
    $endDt = date("m-d-Y", strtotime($joinDt));  
    echo "New date format is: ".$endDt. " (MM-DD-YYYY)";  
?>  

Don’t miss : How To Change Date Format In PHP?

Also Read This πŸ‘‰   current month in php

Change DD-MM-YYYY to YYYY-MM-DD

In the below example, i have date 25-07-2015 in DD-MM-YYYY format, and i will convert this to 2015-07-25 (YYYY-MM-DD) format.

<?php  
    $joinDt = "25-07-2015";  
    $endDt = date("Y-m-d", strtotime($joinDt));  
    echo "New date format is: ".$endDt. " (YYYY-MM-DD)";  
?>  

Result
New date format is: 2015-07-25 (YYYY-MM-DD)

Change DD-MM-YYYY to YYYY/MM/DD

Suppose i have date 25-07-2015 in DD-MM-YYYY format separated by dash (-) sign. i want to convert this to 2015/07/25 (YYYY/MM/DD) format

<?php  
    $joinDt = "25-07-2015";  
    $date = str_replace('-"', '/', $joinDt);  
    $endDt = date("Y/m/d", strtotime($date));  
    echo "New date format is: ".$endDt. " (YYYY/MM/DD)";  
?>  

Result

 date format is: 2015/07/25 (YYYY/MM/DD)

Change date time to another format

<?php  
    $date = "06/13/2022 5:35 PM";  
    //converts date and time to seconds  
    $sec = strtotime($date);  
    //converts seconds into a specific format  
    $endDt = date ("Y/d/m H:i", $sec);  
    //Appends seconds with the time  
    $endDt = $endDt . ":00";  
    // display converted date and time  
    echo "New date time format is: ".$endDt;  
?>  

I hope you get an idea about convert mysql date to dd mm yyyy format in php.
I would like to have feedback on my infinityknow.com.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.