I finally found a way around which seems quite clean. The trick is to force Laravel to use datetime2
instead of datetime
with SQL Server.
In order to do this you need to do those changes:
In Illuminate/Database/Schema/Grammars/SqlServerGrammar.php
protected function typeDateTime(Fluent $column)
{
return 'datetime'; // Change to datetime2
}
And
protected function typeTimestamp(Fluent $column)
{
return 'datetime'; // Change to datetime2
}
Then in Illuminate/Database/Query/Grammars/SqlServerGrammar.php:
public function getDateFormat()
{
return 'Y-m-d H:i:s.000'; // change to 'Y-m-d H:i:s.0000000'
}
I hope it helps someone...