I’m using fixtures load to write to a datetime field of an entity.
Entity:
/** @ORM\Column(type="datetime", nullable=true) */
protected $date;
I use the following method to set the date:
public function setDate($date='')
{
$fecha = new \DateTime($date);
$fecha = $fecha->format('Y-m-d');
$this->date = $fecha;
}
I only want to use the year, month, day in order to get a sum with a group by dql-query.
When I implement fixtures load I get the following error message:
Fatal error: Call to a member function
format()on a non-object in C:\xampp\htdo
cs\brel\vendor\doctrine-dbal\lib\Doctrine\DBAL\Types\DateTimeType.php on line 44
What am I doing wrong here?
Doctrine’s
date,timeanddatetimefields assume that the class property is a \DateTime-instance, not a formatted date-string (the formatting is done via the Type-Mapping in Doctrine DBAL).You can either create a custom Type (see Doctrine DBAL-documentation) or use a different type (string?).