Milliseconds value are not getting saved in SQL Server DateTime column

c# dapper sql-server

Question

I need to store a DateTime value which is sent to the Database from a C# application which is using DateTime.UtcNow. If I save it to the DateTime column, the milliseconds value are always 000. But while debugging from the application, the milliseconds value is sent from the application to the database. What am I missing?

Popular Answer

Here's no pleasant way to use Datetime because

SQL Server only stores time to approximately 1/300th of a second. These always fall on the 0, 3 and 7 milliseconds

SQL Server 2008 has much more precision available. The datetime2 datatype will accurately store values like this: 2008-12-19 09:31:38.5670514

See reference documentation



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why