I have an entity with one column of "datetime" type to store a timestamp.
/** * @ORM\Column(type="datetime") */ protected $timestamp;
I had MySQL 5.5.40 and I discovered it does not store microseconds. So I switched to 5.6.21 and imported all my tables and data.
I tried to declare the type as
* @ORM\Column(type="datetime(6)")
but it gave me an error. So I changed it directly in the DB by doing:
ALTER TABLE symfony.hrmgmt MODIFY timestamp DATETIME(6);
In my controller I do this:
$dt = new \DateTime('now'); $newHREvent->setTimestamp($dt);
But nonetheless the timestamp is stored without fractions of second.
I can (now) manually enter datetime with fractional values via SQL, but when I do it through my controller it always stores with .000000
I suppose that's because Doctrine does not know that it can store also microseconds.
My PHP version is still 5.4.34.
Thank you!
To create a datetime with microsecond you have to use DateTime::createFromFormat
in your controller
$date = \DateTime::createFromFormat('U.u', (string)microtime(true));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With