title: Doctrine with SQL Server DateTime type
body: <p>I work on a Web application on Laravel which relies on Doctrine. The Database is stored on SQL Express 2017.</p>
  
  <p>I had a problem with the DateTime type as mentioned in the <a href="https://www.doctrine-project.org/projects/doctrine-dbal/en/2.8/reference/known-vendor-issues.html#microsoft-sql-server" rel="nofollow noreferrer">documentation</a> when I do a SELECT.</p>
  
  <p><strong><em>Could not convert database value "2018-11-19 16:19:44.923" to Doctrine Type datetimetz. Expected format: Y-m-d H:i:s.u P</em></strong></p>
  
  <p>To solve this I created my own DateTime Type after some research.</p>
  
  <pre><code>&lt;?php
  
  namespace App\Doctrine\Types;
  
  use Doctrine\DBAL\Types\DateTimeType;
  use Doctrine\DBAL\Platforms\AbstractPlatform;
  
  class MsDateTime extends DateTimeType
  {
      private $dateTimeFormatString = 'Y-m-d H:i:s.u';
  
      public function convertToDatabaseValue($value, AbstractPlatform $platform)
      {
          return ($value !== null) ? $value-&gt;format($this-&gt;dateTimeFormatString) : null;
      }
  
  }
  </code></pre>
  
  <p>Then I override the default type :</p>
  
  <pre><code>Type::overrideType(Type::DATETIMETZ, 'App\Doctrine\Types\MsDateTime');
  </code></pre>
  
  <p>So now I can display data but I can't insert new rows :
  <em>An exception occurred while executing 'INSERT INTO table (row1, row2, active, date_created, timestamp) VALUES (?, ?, ?, ?, ?)' with params ["Test", "Test", 1, "2018-11-20 16:12:11.349245", "2018-11-20 16:12:11.349250"]</em></p>
  
  <p>I would like to know why I can't store new rows. If you have any fix for Doctrine with SQLServer I would be very grateful !</p>
  
  <p>We also use Python with SQL Alchemy to query the same database and we don't have this kind of problem.</p>