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.
convert mysql date to dd mm yyyy format in php
Contents
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?
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.
I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I’m a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.