c# - Why does the datetime type in SQL Server Compact round values? -
i've run across surprised me.
i using winpcap collect data off network. internally, winpcap uses windows performance counters generate timestamps. know subject drift, these timestamps nevertheless have precision down microsecond level.
if insert these timestamps sql server compact 4.0 database datetime value , extract them later, noticed precision has dropped milliseconds.
for example,
10:52:19.706084 -> 10:52:19.706000 now, have since read here sql server rounds values datetime type .000, .003, or .007 milliseconds. explains happening.
now, datetime field uses 8 bytes store data, 4 bytes date , 4 milliseconds since midnight. if call datetime.tobinary(), 8-byte number represents value in of precision. in fact, if write value database in bigint column , call datetime.frombinary() when extracting value, original value same precision.
this approach i'm going use, i'm still curious: why didn't original datetime type in sql server compact use datetime's tobinary/frombinary storage mechanism?
edit:
as aaron bertrand rightly points out, sql compact not support datetime2. further, datetime2 uses 6, 7, or 8 bytes, not 54 bytes in regular sql server. basic question still stands, though.
i don't know full internal details or motivation behind choice, datetime stored internally - - 2 4-byte integers. 1 represents date, other represents time. suspect lose precision in latter because of way ticks / milliseconds have been handled since first versions of sql server, again, don't know low-level implementation details.
related questions more background info:
what internal representation of datetime in sql server?
allow entity framework 4.5 use datetime2 sql server ce4
in order support precision want without moving value in , out of binary format, suggest using localdb has same portability advantages of compact without many of feature limitations (such support more precise datetime2 type - assure takes 6-8 bytes, not 54 :-)).
Comments
Post a Comment