I have an issue that I have been dealing for way to long
Please look at the code below: ( I have commented on the right the values that I get when I debug the variable)
When input is for example “0000-00-00 00:00:00”
$date1 = ($date['confirmed_at']); //value of $date1 is "0000-00-00 00:00:00"
$date2 = strtotime($date1); //value of $date2 is "1"
$date3 = date('y-m-d',$date2); //value of $date3 is "70-01-01"
When input is for example “2011-09-12 08:57:26”
$date1 = ($date['confirmed_at']); //value of $date1 is "2011-09-12 08:57:26"
$date2 = strtotime($date1); //value of $date2 is "1315817846"
$date3 = date('y-m-d',$date2); //value of $date3 is "11-09-12"
I’m a bit confused with the values that I have been getting…
All that I am trying to do is take the date which is currently in a “YYYY-MM-DD HH-MM-SS” and convert it into a “YYYY-MM-DD” format.
What you’re seeing in the first example results from the fact, that
strtotime()returns a unix timestamp, that is a number of seconds since Jan 1st, 1970. It just can’t return anything sensible for0000-00-00 00:00:00.For
YYYY-MM-DDformat usedate('Y-m-d')