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$time = strtotime('10/16/2003');
2
3$newformat = date('Y-m-d',$time);
4
5echo $newformat;
6// 2003-10-16
7
1$s = '06/10/2011 19:00:02';
2$date = strtotime($s);
3echo date('d/M/Y H:i:s', $date);
4The above one is the one of the example of converting a string to date.
5echo $s ->format('Y-m-d');
6The above one is another method
1$s = '08/11/2010 19:37:02';
2$date = strtotime($s);
3echo date('Y-m-d H:i:s', $date);
1$originalDate = "2010-03-21";
2$newDate = date("d-m-Y", strtotime($originalDate));
1phpCopyecho $dateNew = DateTime::createFromFormat('m-d-Y', '03-08-2020')->format('Y/m/d');
2//output: 2020/03/08
3