Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server datetime rounding

According to MSDN "Rounding of datetime Fractional Second Precision" it should truncate the following Date when saving into a datetime column:

new DateTime(635180453197748530L)  //22 October 2013 13:28:39.7748530
// write to SQL server and re-read it
// result should be = 6351804531977 3 0000L

However, it is reproducible 6351804531977 7 0000L. Is this a bug or do I have any problems in my understanding of the algorithm?

(we use Entity Framework for read/write to DB)

like image 930
D.R. Avatar asked Feb 24 '26 05:02

D.R.


1 Answers

Sometimes before I write a datetime to the database, I cast it to SqlDateTime, which I have found produces much more predictable results with regards to rounding/truncation than simply writing the CLR datatype to the database directly.

like image 54
Robert N Avatar answered Feb 26 '26 19:02

Robert N



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!