In this post we will show you date format in php, hear for date format php we will give you demo and example for implement.
Throughout, In this tutorial you’ll learn php date.now.This article goes in detailed on implementing php format date from mysql.If you want to learn string to date php. So, from this post, you can find step by step process of doing php date to timestamp.
How do I Convert Date Format in PHP?
There are the Following The simple About how to print current date in php? Full Information With Example and source code.
As I will cover this Post with live Working example to develop how to get current date and time in php?
1. Change YYYY-MM-DD => MM-DD-YYYY
Here we have date yyyy-mm-dd (“2021-04-25”) format and converting it to mm-dd-yyyy (“04-25-2021”) format.
$origDate = "2021-04-25"; $newDate = date("m-d-Y", strtotime($origDate)); echo $newDate; //results : 04-25-2021
2. Change YYYY-MM-DD => DD-MM-YYYY
Here we have date yyyy-mm-dd (“2021-04-25”) format and converting it to dd-mm-yyyy (“25-04-2021”) format.
$origDate = "2021-04-25"; $newDate = date("d-m-Y", strtotime($origDate)); echo $newDate; //results 25-04-2021
3. Change DD/MM/YYYY => YYYY-MM-DD
If you have slashes in date format like “25/04/2021” and need to convert / with hyphens (-). The following example will help you to convert DD/MM/YYYY (“25/04/2021”) to YYYY-MM-DD (2021-04-25).
$origDate = "25/04/2021"; $date = str_replace('/', '-', $origDate ); $newDate = date("Y-m-d", strtotime($date)); echo $newDate; //result : 2021-04-25
I hope you get an idea about how to convert date format in php?.
I would like to have feedback on my pakainfo.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.