Enabling microseconds in Symfony2 (Doctrine) and MySQL Enabling microseconds in Symfony2 (Doctrine) and MySQL symfony symfony

Enabling microseconds in Symfony2 (Doctrine) and MySQL


To create a datetime with microsecond you have to use DateTime::createFromFormat in your controller

$date = \DateTime::createFromFormat('U.u', (string)microtime(true));


tl;dr #

Follow this blog, create your own custom data type and use ithttps://blog.tomhanderson.com/2018/09/datetime-with-microseconds-for-mysql-in.html

For the patient and curios ones

I am coming here after having gone through the exact steps that you mentioned, upgrading mysql, changing column datatype precision manually, and I was at the exact state as you are...

This is not got to do with PHP version, but instead Doctrine has a role to play here.

Just like for decimal values doctrine supports precision and scale type="decimal" Ex: precision=10, scale=2, it should have supported for datetime, however it doesn't at the moment

The issue is currently being tracking here https://github.com/doctrine/dbal/issues/2873

However, there is a blog that explains a workaround until doctrine fixes this at their endhttps://blog.tomhanderson.com/2018/09/datetime-with-microseconds-for-mysql-in.html

I believe it was written by Tom H Anderson