I’ve run into a small programming problem. I need to do some time calculations, but as an input I only have a string – so basically I’ll need to convert this string to a date/time object in PHP. It’s the conversion I’m having trouble with.
$endtimestamp = "September 1, 2012 13:00 PM";
$doesntwork = strtotime(trim($endtimestamp));
$doesntwork2 = date_create_from_format("l, F j, Y G:i A", $endtimestamp);
$doesntwork3 = date("l, F j, Y G:i A", strtotime($endtimestamp));
To be quite honest, I have no idea why these functions don’t work as they are supposed to. SO far, other online resources have been vague at best. Can anyone tell me what I’m doing wrong?
There are 2 problems here.
One is that
13:00 PMdoesn’t make any sense. It’s either1:00 PMor13:00.Also your format
l, F j, Y G:i Adoesn’t match your input string.Either the format should be:
F j, Y G:i A, or the string should beSaturday, September 1, 2012 13:00 PM.