convert string to time php code example
Example 1: php convert us date to european
$originalDate = "2010-03-21";
$newDate = date("d-m-Y", strtotime($originalDate));
Example 2: string to datetime php
$s = '06/10/2011 19:00:02';
$date = strtotime($s);
echo date('d/M/Y H:i:s', $date);
Example 3: 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 4: strtotime format
$date = '25/05/2010';
$date = str_replace('/', '-', $date);
echo date('Y-m-d', strtotime($date));
Example 5: php date to seconds
<?php
$str = 'Tue Dec 15 2009';
$timestamp = strtotime($str);
echo $timestamp;
?>
Example 6: Convert String to Date and Date-Time in PHP
phpCopyecho $dateNew = DateTime::createFromFormat('m-d-Y', '03-08-2020')->format('Y/m/d');