Doctrine 2 - How to use the Time column type

I have a problem with the Time column type: I have this part of my "Match" entity:

/**
 * @ORM\Column(type="date")
 */
private $creationDate;
/**
 * @ORM\Column(type="time",nullable=true)
 */
private $creationTime;

      

And every time I try to save the entity, I get the error:

Error: Call in format member function () on string in TimeType.php

This is the part where I fill in the CreationTime:

$time = date("H:i:s",strtotime(date("Y-m-d H:i:s")));

$Match->setCreationTime($time); 

      

I tried to check the TimeType.php file and I found out that this function is the source of the problem:

public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
    return ($value !== null)
        ? $value->format($platform->getTimeFormatString()) : null;
}

      

to be more sure, I checked the AbstractPlatform class and found out that the getTimeFormatString member method always returns this string: "H: i: s".

So any organ can help?

+3


source to share


1 answer


try using this:



$Match->setCreationTime(new \Datetime());

      

+1


source







All Articles