SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Datetime precision


Datetime precision

Author
Message
Steve Jones
Steve Jones
SSC Guru
SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)

Group: Administrators
Points: 62829 Visits: 19111
the dateadd is not commented out, just the note.

SQL is only precise to .0, .3, and .7ms, therefore you can't have .1 as the answer. It could only be one of those 3

Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
SQLBOT
SQLBOT
SSC Eights!
SSC Eights! (956 reputation)SSC Eights! (956 reputation)SSC Eights! (956 reputation)SSC Eights! (956 reputation)SSC Eights! (956 reputation)SSC Eights! (956 reputation)SSC Eights! (956 reputation)SSC Eights! (956 reputation)

Group: General Forum Members
Points: 956 Visits: 836
jim.taylor (11/30/2009)
I'm confused, if DateTime is only precise to 3.33 ms, why then is the answer just 1 ms off? Why not 3 ms?


SQL Server rounded down to 100 ms from the 101ms that was added.
if you add 102ms it rounds up to 103 ms.

I posted this question because the inaccuracy caught me off guard a couple months ago when I kept getting unexpected results out of some code.

After suspecting sheer lunacy to be the root cause, I finally got the notion that maybe the SQL Server clock was dodgy. I wrote the query that you see in the question to test that theory and the BOL confirmed the rest.

To avoid the issue, use datetime2 which is more precise, but still has the same problem when you get down to 100 nanoseconds.

My issue was resolved by ignoring milliseconds since I didn't need to be that precise, and accuracy was more important than precision.

Thanks All!

~Craig

Craig Outcalt



Tips for new DBAs: http://www.sqlservercentral.com/articles/Career/64632
My other articles: http://www.sqlservercentral.com/Authors/Articles/Craig_Outcalt/560258
Michael Poppers
Michael Poppers
SSC Eights!
SSC Eights! (829 reputation)SSC Eights! (829 reputation)SSC Eights! (829 reputation)SSC Eights! (829 reputation)SSC Eights! (829 reputation)SSC Eights! (829 reputation)SSC Eights! (829 reputation)SSC Eights! (829 reputation)

Group: General Forum Members
Points: 829 Visits: 416
jim.taylor (11/30/2009)
...if DateTime is only precise to 3.33 ms, why then is the answer just 1 ms off? Why not 3 ms?

When the SELECT output's ms aspect can be one of 100 (from 99.9) or 103 (from 103.23), 100 is closer :-).

I chose the wrong answer because I was thinking of roundoff in 3ms increments instead of in 3.33ms increments (although I should have realized that the choice should then have been between 99 and 102 :-)), so thank you to the questioner!
Dan Guzman - Not the MVP
Dan Guzman - Not the MVP
SSC Eights!
SSC Eights! (908 reputation)SSC Eights! (908 reputation)SSC Eights! (908 reputation)SSC Eights! (908 reputation)SSC Eights! (908 reputation)SSC Eights! (908 reputation)SSC Eights! (908 reputation)SSC Eights! (908 reputation)

Group: General Forum Members
Points: 908 Visits: 741
Based on all the comments here, I got completely lucky.

I assumed it was a trick question, and figured Midnight was one of those mystery values between today and yesterday, and that 1 millisecond was 'consumed' in the math. I'm clearly thinking way to hard about these QotDs.
Tom Garth
Tom Garth
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1251 Visits: 1499
peter.house (11/30/2009)
While looking at the answer choices, my brain kept saying "Yesterday Midnight + 100ms"

For me, Midnight today is tonight and the SQL answer is this morning at 100ms after midnight or 100ms after the beginning of day.


The time element for midnight is 0, not 24. If it were 24 then the answer would have been 101 ms after midnight (tomorrow morning).Hehe

Tom Garth
Vertical Solutions

"There are three kinds of men. The one that learns by reading. The few who learn by observation. The rest of them have to pee on the electric fence for themselves." -- Will Rogers

Bhavesh_Patel
Bhavesh_Patel
Say Hey Kid
Say Hey Kid (679 reputation)Say Hey Kid (679 reputation)Say Hey Kid (679 reputation)Say Hey Kid (679 reputation)Say Hey Kid (679 reputation)Say Hey Kid (679 reputation)Say Hey Kid (679 reputation)Say Hey Kid (679 reputation)

Group: General Forum Members
Points: 679 Visits: 297
I am confused !



Bhavesh Patel

http://bhaveshgpatel.wordpress.com/
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search