This tutorial uses PHP strtotime() and date() functions to convert date time format. For example you have stored a date YYYY-MM-DD format in a variable and need to change this to MM-DD-YYYY format. We can achive this by converting date first to seconds using strtotime() function. After that reconstruct date to any format using date() function. Below is few examples of conversion: 1. Change YYYY-MM-DD => MM-DD-YYYY Here we have date yyyy-mm-dd (“2019-01-15”) format and converting it to mm-dd-yyyy (“01-15-2019”) format.
1 2 3 4 | $origDate = "2019-01-15"; $newDate = date("m-d-Y", strtotime($origDate)); echo $newDate; |
Output: 01-15-2019 2. Change YYYY-MM-DD => DD-MM-YYYY Here we have date yyyy-mm-dd (“2019-01-15”) format and converting it to…