Today, I came across something confusing for me with the behavior of the \DateTime::createFromFormat .
In my case, I have a string representing a date in the following m/Y (05/2017) format m/Y (05/2017) . When I want to convert a string to a DateTime object, I ran into the following problem:
$date = \DateTime::createFromFormat('m/Y', '02/2017');
When I unload the $date variable, the $date property inside is '2017-03-03 11:06:36.000000'
But if I add the date to the month $date = \DateTime::createFromFormat('d/m/Y', '01/02/2017'); , I will return the object with the correct date. (unfortunately, I cannot change the date format and add the day. It must be m / Y).
The fix I came up with is to associate the first day of the month with a date string, I have $date = '01/'.$dateString; , but I do not want to do this because it is hard-coded.
What is wrong here? Is there a createFromFormat function with information on how to create an object? I am very confused about this. Thanks for any help in advance!
source share