Datetime to string PHP
<?php
$date = new DateTime('2000-01-01');
echo $date->format('Y-m-d H:i:s');
?>
Beautiful Baboon
<?php
$date = new DateTime('2000-01-01');
echo $date->format('Y-m-d H:i:s');
?>
$s = '06/10/2011 19:00:02';
$date = strtotime($s);
echo date('d/M/Y H:i:s', $date);
<?php
$date = '27/06/2020, 04:42:43 PM';
$date = str_replace('/', '-', $date);
echo date('F j, Y, g:i a',strtotime($date));
// output : June 27, 2020, 4:42 pm
?>
Date to string
$date = "2021/03/13";
$newdate= date('d M, Y', strtotime($date));
echo $newdate;
$old_date = date('l, F d y h:i:s'); // returns Saturday, January 30 10 02:06:34
$old_date_timestamp = strtotime($old_date);
$new_date = date('Y-m-d H:i:s', $old_date_timestamp);
phpCopy$theDate = new DateTime('2020-03-08');
echo $stringDate = $theDate->format('Y-m-d H:i:s');
//output: 2020-03-08 00:00:00