Question:
In a DB web app, Date/Time field is very common.
When in Symfony, you tried to do either of the follwings:
$creationDate=new DateTime();
$record->setCreationDate($creattionDate);
This will create a "Object DateTime can't be converted to string" error.
Or:
$creationDate=new DateTime();
$datestr=$creationDate->format('Y-m-d H:i:s');
$record->setCreationDate($datestr);
This will create "Calling method format() on a non-ojbect" error.
Solution:
Hack the DateTimeType.php located at: your symfony root/vendor/doctrine/dbal/lib/Doctrine/DBAL/Types/DateTimeType.php for the function named
convertToDatabaseValue
Original content:
It seems Symfony is doing some extra conversion when the parameter is already a string.
Change to:
will do the trick.
In your entity you have to map your field with date or datetime type.
@ORM\Column(name="creationDate", type="date", nullable=true)