For future readers who will surely ever run into this problem (this is the first post if you google "symfony 2 datetime from string"), keep in mind that in Symfony 2 DateTime an object DOES NOT accept a string with this format: "d/m/YH:i:s" and probably also doesn't support many others.
In order not to become insane , I really found that the simplest and safest solution to avoid such errors is this one:
First, get your string date from any of your request (in my case, a general AJAX request) and convert it to a DateTime Object , this example assumes that we need to create a dateTime object for 25/04/2015 15:00 , which is jQuery UI italian DateTimePicker format (this is just an example):
$literalTime = \DateTime::createFromFormat("d/m/YH:i","25/04/2015 15:00");
(note: use \ to use the php DateTime object, otherwise you will use the symfony datetime object that throws you an exception)
Then, once you have done this, create a date string using the function , specifying the expected output format ( Ymd H:i:s ) as the first parameter:
$expire_date = $literalTime->format("Ymd H:i:s");
That way, you are 100% sure that any format you send or receive will be correctly converted, and you will not receive any exception to the Symfony DateTime object , while you provide what you expect as input .
Knowing that this post is actually quite old, I only decided to publish it because I could not find another valuable source, but this one, in order to understand where the problem might be.
Please note that the best solution is still to send the datetime string in the correct format, but if you literally have no way to do this, the safest way to convert such a string is as described above.