datetime to string php code example
Example 1: string to datetime php
$s = '06/10/2011 19:00:02';
$date = strtotime($s);
echo date('d/M/Y H:i:s', $date);
Example 2: php mysql date format
date("Y-m-d H:i:s")
Example 3: Datetime to string php
<?php
$date = new DateTime('2000-01-01');
echo $date->format('Y-m-d H:i:s');
?>
Example 4: time to string in php
<?php
$date = '27/06/2020, 04:42:43 PM';
$date = str_replace('/', '-', $date);
echo date('F j, Y, g:i a',strtotime($date));
?>
Example 5: Convert DateTime to String in PHP
phpCopy$theDate = new DateTime('2020-03-08');
echo $stringDate = $theDate->format('Y-m-d H:i:s');
Example 6: date to string php
$date_string_prepared = date_create("2020-08-07");
$date_string = $date_string_prepared->format("d M Y");