DateTime.Ticks is not the same after saving it in SqlServer

  • Thread starter Thread starter Larry
  • Start date Start date
L

Larry

Can someone explain why DateTime value are not save correctly.
Here is what happen:
I put DateTime.Now in a column
Read it back and compare the Ticks values and they are off a bit.


UnitTest.TestSaveDateTime :
expected:<632621000979676250>
but was:<632621000979670000>


Larry
 
Larry,

Did you know that they are completly different. The ticks in the system are
in 100-nanosecond (whatever that is) units at 00010101 while the sql server
starts at the introduction of the Georgian calandar in the Brittish Empire.

Cor
 
Larry said:
Can someone explain why DateTime value are not save correctly.
Here is what happen:
I put DateTime.Now in a column
Read it back and compare the Ticks values and they are off a bit.


UnitTest.TestSaveDateTime :
expected:<632621000979676250>
but was:<632621000979670000>

I suspect it's because DateTime.Ticks is defined as a number of
100-nanosecond intervals, i.e. its units are 10**-7 seconds, whereas the SQL
Server datetime data type only has an accuracy of 1/300th of a second. Thus
when you store DateTime.Now in the database it will be rounded to the
nearest 1/300th of a second.

Chris Jobson
 
Back
Top