Php strtotime return 1970-01-01

<?php
$a = 'MAY 05, 2001  00:54:00 AM';

echo date('Y-m-d',strtotime($a)).'<br />';

$b = 'MAY 05, 2001  05:54:00 AM';

echo date('Y-m-d',strtotime($b)).'<br />';

//MAY 05, 2001  00:54:00 AM return 1970-01-01
//MAY 05, 2001  05:54:00 AM return 2001-05-05

?>

      

+3


source to share


3 answers


AM

assumes that you are using a 12 hour clock . However, there is no "zero hour" in this clock system, so your first example is 00:54:00 AM

not a valid time (12 hour clock runs from one to twelve and then reverts to one with am / pm toggle). Perhaps you meant simply 00:54:00

( 24 hour clock) or 12:54:00 AM/PM

(this would be six minutes to one hour).



+3


source


You have completed AM in 24-hour time format. I fixed it



$a = 'MAY 05, 2001 00:54:00';

echo date('Y-m-d',strtotime($a)).'<br />';

$b = 'MAY 05, 2001  05:54:00 AM';

echo date('Y-m-d',strtotime($b)).'<br />';

      

+2


source


If you are using PHP version lower than 5.3.0 you can use

http://www.php.net/manual/tr/function.date-parse-from-format.php

like

$a = 'MAY 05, 2001 00:54:00';

echo date('Y-m-d',date_parse_from_format("F d, Y H:i:s",$a)).'<br />';

      

0


source







All Articles