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


Fun(?) with DATETIME2


Fun(?) with DATETIME2

Author
Message
Richard Warr
Richard Warr
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2780 Visits: 1987
Comments posted to this topic are about the item Fun(?) with DATETIME2

_____________________________________________________________________
MCSA SQL Server 2012
TomThomson
TomThomson
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14134 Visits: 12197
I learned something here - I expected it to fail because I thought datetime2 literals were required to specify time to the second (or more precisely), so I got it wrong.

However, the explanation is complete nonsense: there is no imaginable way that something expressing dates in the Gregorian calendar would fail to recognise 9th September 1752, just because some countries didn't at that time use the Gregorian calendar - most of the civilised world (all of the civilised world except Scotland and Ireland, who were unfortunately controlled by the uncivilised English :laughSmile adopted the Gregorian calendar well before that date, but even if no-one had yet adopted it the SQL type is not intended to express anything other than Gregorian dates. http://msdn.microsoft.com/en-us/library/bb677335%28v=SQL.100%29.aspx explicitly states that the calendar for datetime2 is Gregorian. It is utterly irrelevant that the benighted English (and their American colonies) called that day the 28th of August, in the Gregorian calendar and hence in datetime2 that day is called the 9th of September.

Tom

Richard Warr
Richard Warr
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2780 Visits: 1987
I wasn't expecting the question to appear today - I was advised it would be tomorrow. That would have given me the opportunity to express the "fun" side of the question as something lightweight for the holidays.

And whilst the explanation may indeed be "complete nonsense" according to BOL it does illustrate the differences that sometimes arise between the real world and one that exists purely of logic.

So, apologies for any upset caused. It was just supposed to be a bit of Christmas cheer.

_____________________________________________________________________
MCSA SQL Server 2012
TomThomson
TomThomson
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14134 Visits: 12197
Richard Warr (12/26/2010)
I wasn't expecting the question to appear today - I was advised it would be tomorrow. That would have given me the opportunity to express the "fun" side of the question as something lightweight for the holidays.

And whilst the explanation may indeed be "complete nonsense" according to BOL it does illustrate the differences that sometimes arise between the real world and one that exists purely of logic.

So, apologies for any upset caused. It was just supposed to be a bit of Christmas cheer.

No apologies needed, because no upset caused. As I said, I learned something from the question, and that is the only thing about QoTD that matters. So from where I stand, it was a really good question (questions I get right are somewhat boring) - and the fact that the explanation contains a bit of a red herring doesn't really matter.

But don't be surprised if someone who does know the data type and also knows that datetime2 literals as short as 10 characters are allowed answers "it works as expected" and then moans that they want their point back when told that's wrong.

Tom

Koen Verbeeck
Koen Verbeeck
One Orange Chip
One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)

Group: General Forum Members
Points: 27021 Visits: 13268
I like the point the question tries to make, but I have however some issues with the answers: how would you know what people expect? If someone not from the former British empire expects it to work, then answer A should be correct. In my country, 9 september 1752 is a perfectly valid date. I expected it to fail because there was no precision specified for the datetime2 datatype (I should check BOl to see if there is a default). So I got the question right for the wrong reason.

Conclusion: great question, but the answers could have been worked out better :-D


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
gserdijn
gserdijn
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1399 Visits: 816
The transition from Julian to Gregorian Calendar: http://www.rundetaarn.dk/engelsk/observatorium/gregorian.html
September 14th 1752 - England and Scotland with colonies. Thursday, September 14th came after Wednesday, September 2nd.

Hmm, undoubtedly this Q will come once again. But for a different country... like Holland. ;-)
(Which should be The Netherlands by the way, but I digress)



Dutch Anti-RBAR League
Nakul Vachhrajani
Nakul Vachhrajani
SSCrazy
SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)

Group: General Forum Members
Points: 2208 Visits: 2143
This question and it's response will invite mixed response, I am sure.

While it is good to know that DATETIME2 removes the "1753" restriction, it should also be known that logical validation of the value is NEVER done during assignment. This is why many (including me) would have expected the correct answer to be that it would run successfully (and it does!).

I would have expected the error if we had been validating the value with something like:


SELECT ISDATE('1752-09-09')



My deduction is that the question simply checks whether proper value assignment is done or not, which is done. It does not check for validity of the value, and hence that should not have been expected when building the answer to the question or in the explanation.

Happy Holidays!

Thanks & Regards,
Nakul Vachhrajani.
http://nakulvachhrajani.com
Be courteous. Drive responsibly.

Follow me on
Twitter: @sqltwins
Google Plus: +Nakul
Carlo Romagnano
Carlo Romagnano
SSCarpal Tunnel
SSCarpal Tunnel (4.8K reputation)SSCarpal Tunnel (4.8K reputation)SSCarpal Tunnel (4.8K reputation)SSCarpal Tunnel (4.8K reputation)SSCarpal Tunnel (4.8K reputation)SSCarpal Tunnel (4.8K reputation)SSCarpal Tunnel (4.8K reputation)SSCarpal Tunnel (4.8K reputation)

Group: General Forum Members
Points: 4830 Visits: 3325
I learned more from QotD of last friday: "what type of shirts does Steve Jones wear on Fridays?"

I run on tuttopodismo
cdiebolt
cdiebolt
SSC Eights!
SSC Eights! (887 reputation)SSC Eights! (887 reputation)SSC Eights! (887 reputation)SSC Eights! (887 reputation)SSC Eights! (887 reputation)SSC Eights! (887 reputation)SSC Eights! (887 reputation)SSC Eights! (887 reputation)

Group: General Forum Members
Points: 887 Visits: 292
Although I can understand the humor behind the question, I can't agree with the official result. ;-)

First, by 1700, the Gregorian calendar had been adopted by most of Europe (including Italy, Portugal, Spain, France, Austria, Germany, Poland, Scotland, Island, Greenland) and most of the colonies of South and Central America. So for the official answer to have a chance of being right, the question should have mentioned the date was about an event in the English colonies or in England.

Furthermore, the datetime2 is storing dates according to the Gregorian calendar. It is its only purpose.

It's not because a date is older than the adoption of a calendar in a certain country or even the invention of said calendar (1582 for the Gregorian calendar) that you can't express that date in the calendar. A calendar is merely a referential and scientifically, we can express in it whatever date we want.

Such an expression of a date becomes invalid only if you are in a very specific historic setting, like checking dates on correspondences dating from that period, because then the date doesn't make sense from the point of view of the writer of such a correspondence. We are hardly in that case when storing data in database unless you have a time machine and decide to set up a database in the past. Hehe



Latheesh NK
Latheesh NK
SSC Eights!
SSC Eights! (925 reputation)SSC Eights! (925 reputation)SSC Eights! (925 reputation)SSC Eights! (925 reputation)SSC Eights! (925 reputation)SSC Eights! (925 reputation)SSC Eights! (925 reputation)SSC Eights! (925 reputation)

Group: General Forum Members
Points: 925 Visits: 2164
I totally disagree that the question should have a compatibility also. I have SQL server 2008 with compatibility with 8.:-)
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