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 «««56789»»

Fun(?) with DATETIME2 Expand / Collapse
Author
Message
Posted Tuesday, March 29, 2011 9:28 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, August 28, 2014 8:53 PM
Points: 1,388, Visits: 3,039
vikram.gharge (3/29/2011)
SQL Server 2008 brought us some new date types including DATETIME2 .............There's some fun to be had with 1751 as well but we'll leave that for another holiday.


Vikram,

What's your point in copy/pasting the QOD? Did you mean to comment and forgot?
Post #1085640
Posted Friday, July 15, 2011 6:23 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Friday, December 13, 2013 7:56 AM
Points: 939, Visits: 754
Poor question; how do you know what my expectations were?


Post #1142438
Posted Wednesday, August 10, 2011 5:40 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: 2 days ago @ 1:46 PM
Points: 2,604, Visits: 572
I expected it to work and it did ( as it should in most countries except in brittain )

/Håkan Winther
MCITP:Database Developer 2008
MCTS: SQL Server 2008, Implementation and Maintenance
MCSE: Data Platform
Post #1157532
Posted Wednesday, August 10, 2011 9:42 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: 2 days ago @ 11:12 AM
Points: 7,791, Visits: 9,545
hakan.winther (8/10/2011)
I expected it to work and it did ( as it should in most countries except in brittain )

Not in most countries except Britain (note single t), in all countries including Britain. Datetime2 uses the Gregorian calendar, not any other calendar, so it is not a locale dependent type.


Tom
Post #1157758
Posted Wednesday, August 10, 2011 10:06 AM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Wednesday, October 1, 2014 10:48 AM
Points: 4,126, Visits: 3,427
Tom.Thomson (8/10/2011)
. . .
Not in most countries except Britain (note single t), in all countries including Britain. Datetime2 uses the Gregorian calendar, not any other calendar, so it is not a locale dependent type.

Hmm... maybe it is not quite Gregorian. If you run this, --

DECLARE @type2 DATETIME2(7) = '1582-10-10';
PRINT DATEPART( dw, @type2 );

you will get 1, i.e., Monday, but that is wrong because there was no October 10 in 1582.
Post #1157790
Posted Wednesday, August 10, 2011 4:08 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: 2 days ago @ 11:12 AM
Points: 7,791, Visits: 9,545
Revenant (8/10/2011)
Tom.Thomson (8/10/2011)
. . .
Not in most countries except Britain (note single t), in all countries including Britain. Datetime2 uses the Gregorian calendar, not any other calendar, so it is not a locale dependent type.

Hmm... maybe it is not quite Gregorian. If you run this, --

DECLARE @type2 DATETIME2(7) = '1582-10-10';
PRINT DATEPART( dw, @type2 );

you will get 1, i.e., Monday, but that is wrong because there was no October 10 in 1582.


Actually if you have Monday as day 1 you will get 7, because that date is a Sunday in the Gregorian calendar. I suspect you have the US default (datefirst = 7, so dw=1 on Sunday), since you presumably got 1.

I guess you and I mean different things by "The Gregorian Calendar"; if "Gregorian Calendar" means the national calendar of the United Kingdom of Poland and Lithuania, or some of the Italian states, or Spain, or Portugal that date didn't exist (in the national calendars of everywhere else in the Western world it did). If you mean the calendar using the 365.2525 day year in common use throughout the western world, in which today is 10 August 2011, extended backwards and forwards according to its regular rules without limit (which is the most common meaning, I believe) 10 Oct 1582 certainly does exist in that calendar.

Using calendars of particular nations can lead to strange results. For example in England the months of January and February did not legally exist in 1751, but they did exist in Scotland (Scottish Jan 1751 was English Jan 1750; almost everyone in England already used the Scottish dating for everything except legal documents and taxation; it was just the legal system in England that was out of step). Scotland had begun the year on 1 Jan since 1600, while up to and including 1751 England began the year on 25th March. That's where we get our 6 April to 5 April taxation year from - it was 5 April to 4 April from 1752 to 1799, then from 6 April to 5 April from 1800 to 1899 in order to retain the same Julian date; but it wasn't adjusted in 1900, which was the next year when an adjustment would have been needed to maintain the Julian connection (whether because the 1751 act was interpreted differently or because the powers that be had forgotten that that act had been interpreted in 1800 as demanding such an adjustment).


Tom
Post #1158120
Posted Wednesday, August 10, 2011 7:28 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, August 28, 2014 8:53 PM
Points: 1,388, Visits: 3,039
That's a great post, Tom, showing examples of the variety in calendar usage. It's truly fascinating in a way that appeals to my inner "geek". It also provides a great sample of reasons to consider DATETIME2 simply a data type and nothing more. It holds values of dates following certain construction rules (number of days in a month, which is a leap year....), but does not attempt to codify the varieties of calendar adjustments made in different locales over the centuries. I think that's what you were saying too, in the last sentence of the first paragraph.

I think that's a fair thing for MS to have done. If I'm storing dates of historical events in the eighteenth century, then I ought to make any duration calculations aware of the Old Style/New Style break in 1752, or any other anomalies like the Scottish/English calendar difference.
Post #1158156
Posted Wednesday, August 10, 2011 9:58 PM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Wednesday, October 1, 2014 10:48 AM
Points: 4,126, Visits: 3,427
I logged that October 5-14, 1582, unaccounted-for gap as a bug against Windows. (SQL Server gets the weekday via a WinAPI call.)

I was told that this will be “soon” corrected for the cultures (languages) that were on the Roman calendar at that time. Win guys are not exactly sure what to do about countries that converted later; most notably Russian Orthodoxy, which converted only after the October Revolution of 1917. (What do you do if the date and time are marked as GMT but the culture is one of the Eastern Orthodoxies? Any suggestions for precedence of calculation?)

This goes all the way back to The Bard and his oft-quoted “time is out of joint,” which alluded to the fact that when he wrote Hamlet, the English calendar was out of sync with the Roman one.

I guess this means that someone will have to think through comparisons of dates on servers that are set to different cultures. (The mentioned October Revolution, which was logged on October 25, 1917, is now celebrated on November 7.)

Never a dull moment.
Post #1158182
Posted Thursday, August 11, 2011 9:38 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: 2 days ago @ 11:12 AM
Points: 7,791, Visits: 9,545
Revenant (8/10/2011)
I logged that October 5-14, 1582, unaccounted-for gap as a bug against Windows. (SQL Server gets the weekday via a WinAPI call.)

I was told that this will be “soon” corrected for the cultures (languages) that were on the Roman calendar at that time. Win guys are not exactly sure what to do about countries that converted later; most notably Russian Orthodoxy, which converted only after the October Revolution of 1917. (What do you do if the date and time are marked as GMT but the culture is one of the Eastern Orthodoxies? Any suggestions for precedence of calculation?) [/quote
They are going to have real fun for Italy, which at the time was a bunch of city-states some of which converted in 1582 and some of which didn't. Also with Germany and bits of Austria (Holy Roman Empire) which converted piece-meal at later dates. And with the GB locale (different year numbers in different countries), the Netherlands, France, and Denmark. Even in the USA Texas converted to dates back when it was still Spanish, much of the rest of the USA rather later, and the Louisana Territory switched at yet another time. I guess the best they can do (unless they have the sense to do nothing) will be to cobble together some arbitrary meaningless mess which will offend various cultures quite seriously, and pretend they've done something useful.

[quote]This goes all the way back to The Bard and his oft-quoted “time is out of joint,” which alluded to the fact that when he wrote Hamlet, the English calendar was out of sync with the Roman one.
It goes back a long way before that. Some states used 1Jan as official year beginning from more than 300 years before Shakespeare, but the Roman official year never began then.

I guess this means that someone will have to think through comparisons of dates on servers that are set to different cultures. (The mentioned October Revolution, which was logged on October 25, 1917, is now celebrated on November 7.)

Never a dull moment.
Indeed not!


Tom
Post #1158594
Posted Wednesday, September 28, 2011 7:57 AM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Wednesday, October 30, 2013 12:00 AM
Points: 535, Visits: 42
I am disagree with the correct answer of this query..
I got the following result after running the same in Msg window...

1752-09-09 00:00:00.0000000

I use "Microsoft SQL server 2008 R2", Please Explain....
Post #1182485
« Prev Topic | Next Topic »

Add to briefcase «««56789»»

Permissions Expand / Collapse