1To convert the date-time format PHP provides strtotime() and date() function. We change the date format from one format to another.
2
3Change YYYY-MM-DD to DD-MM-YYYY
4<? php.
5$currDate = "2020-04-18";
6$changeDate = date("d-m-Y", strtotime($currDate));
7echo "Changed date format is: ". $changeDate. " (MM-DD-YYYY)";
8?>
1$originalDate = "2010-03-21";
2$newDate = date("d-m-Y", strtotime($originalDate));
1$currDate = "2020-08-25";
2$changeDate = date("d-m-Y", strtotime($currDate));
3echo $changedDate;
1$var = '20/04/2012';
2$date = str_replace('/', '-', $var);
3echo date('Y-m-d', strtotime($date));