Take the 2-minute tour ×  In a DB table I have several fields
with datetime as field type. So I need to persist data only as
date time object.  From a form I get date time as string like
2012-10-05 17:45:54  Now when ever I persist my entity I get
following error:  Fatal error: Call to a member function
format() on a non-object in ..\DateTimeType.php on line 44  I
tried with    $from = \DateTime::createFromFormat('yy-mm-dd
hh:mm:ss', $post['started_at']);  or just  $from = new
\DateTime($post['started_at']);  The last code works but it does
not uses the timestamp passed as arguement but just gets the
current time.  Any ideas?  share|improve this question Are you
sure $post['started_at'] contains what you want it to? Is it not
$_POST['started_at']? –  Second Rikudo Oct 6 '12 at 9:41 Also,
DateTime object and methods throw exceptions on errors. Do you
get none of those? Try using try/catch. –  Second Rikudo Oct 6
'12 at 9:43  2 Answers 2  up vote 4 down vote accepted  i always
create DateTime object with its c