Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Datetime precision Expand / Collapse
Author
Message
Posted Sunday, November 29, 2009 5:27 AM


SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Friday, January 3, 2014 10:59 AM
Points: 626, Visits: 836
Comments posted to this topic are about the item Datetime precision

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
Post #825871
Posted Monday, November 30, 2009 3:15 AM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Monday, March 18, 2013 7:52 PM
Points: 280, Visits: 88
I will personaly prefer to do something like cast(cast(getdate() as int) as datetime) to obtain de date of the day at midnight rather using datediff+dateadd functions.


My MCP Transcript (ID : 692471 Access : 109741229)
Post #826087
Posted Monday, November 30, 2009 5:52 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Friday, July 18, 2014 7:44 AM
Points: 2,243, Visits: 552
The wording of this question is ambiguous - if the question is "what would you expect this query to return", then any answer you select is correct by definition, as it's what you would expect.


Post #826139
Posted Monday, November 30, 2009 6:28 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 4:59 PM
Points: 23,000, Visits: 31,482
Dude76 (11/30/2009)
I will personaly prefer to do something like cast(cast(getdate() as int) as datetime) to obtain de date of the day at midnight rather using datediff+dateadd functions.


There has been several discussions regarding this and iirc it was actually proven that the dateadd/datediff method is actually faster. Also, it doesn't use the knowledge of how datetime values are stored. If MS changes this, the dateadd/datediff method should still work as advertised.



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #826151
Posted Monday, November 30, 2009 6:34 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: 2 days ago @ 6:24 AM
Points: 2,451, Visits: 2,342
SQLBOT (11/29/2009)
Comments posted to this topic are about the item <A HREF="/questions/Datetime+Manipulation/68075/">Datetime precision</A>

Thanks. After year and years working with sql, there always is something to learn.
Post #826153
Posted Monday, November 30, 2009 7:07 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, April 5, 2011 8:15 AM
Points: 137, Visits: 29
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.

Post #826177
Posted Monday, November 30, 2009 7:11 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 7:13 AM
Points: 2,381, Visits: 176
The query returns: 2009-11-30 00:00:00.100. The part about the 101 milliseconds is a commented line. It does not have any effect on the query. Therefore the answer given by the author is incorrect and 2009-11-30 00:00:00.100 is the correct answer.
Post #826182
Posted Monday, November 30, 2009 7:14 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, October 6, 2010 7:54 AM
Points: 126, Visits: 75
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?
Post #826185
Posted Monday, November 30, 2009 7:18 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 7:13 AM
Points: 2,381, Visits: 176
...or is is 1.1 ms short...or 2.23 ms over? Are we rounding somewhere?
Post #826187
Posted Monday, November 30, 2009 7:21 AM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Monday, March 18, 2013 7:52 PM
Points: 280, Visits: 88
Lynn Pettis (11/30/2009)
Dude76 (11/30/2009)
I will personaly prefer to do something like cast(cast(getdate() as int) as datetime) to obtain de date of the day at midnight rather using datediff+dateadd functions.


There has been several discussions regarding this and iirc it was actually proven that the dateadd/datediff method is actually faster. Also, it doesn't use the knowledge of how datetime values are stored. If MS changes this, the dateadd/datediff method should still work as advertised.

Oh, faster rather cast, really ?
I didn't know that, and were sure that cast were a fast operation front of manipulating functions.
Thx for the info, i'll test if to have an idea of the difference of performance.



My MCP Transcript (ID : 692471 Access : 109741229)
Post #826188
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse