My code
$time = "Tuesday, 26 June 2012";
//str_replace(',','',$time);<--this also doesn't work.
$a = strptime($time, "%l, %j %F %Y");
$stmp = mktime(0,0,0,$a['tm_mon'],$a['tm_mday'],$a['tm_year'],0);
$from_stmp = date("l, j F Y H:i:s", $stmp);
echo $from_stmp; //Tuesday, 30 November 1999 00:00:00
Now i know there is a more elegant way, that actually works:
$time = "Tuesday, 26 June 2012";
$stmp = strtotime($time);
$from_stmp = date("l, j F Y H:i:s", $stmp);
echo $from_stmp;//Tuesday, 26 June 2012 00:00:00
But what’s wrong with the first version? I’m just curious.
Problem #1
You wrote
time; it should be$time.Problem #2
Your format string is wrong.
strptimedoesn’t use the same format strings asdate, just with percentage signs in front; it has its own set. Your format string should look like this:Problem #3
strptimereturns a number of years since 1900. You need to add1900.strptimereturns a month from 0 to 11. You need to add1.All summed up
Here’s your code, fixed:
Hooray, it works!