I have the following string assigned to a variable:
$date = "16 June, 2012, 13:00pm";
I’m running it through createFromFormat to try and convert it to a DateTime Object:
$dateTime = DateTime::createFromFormat("d M, Y, H:ia", $date);
This is object that I get back:
DateTime Object
(
[date] => 2012-06-17 01:00:00
[timezone_type] => 3
[timezone] => Europe/Dublin
)
I’m not sure what I’m doing wrong to be honest, the format used in createFromFormat looks to match that of the input string, but the output is wrong. In this example, the day is the 17th instead of the 16th and the time is showing 01:00:00 instead of 13:00:00
Any ideas or pointers would really help,
PM is interpreted by
DateTimeas “Add +12 hours to the result”, which is throwing your date off balance.Simple solution: drop the PM, or have a 12-hour clock version (i.e. 1:00pm)