Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase ««12

The SQL Server 2008 Datetimeoffset Data Type Expand / Collapse
Posted Monday, April 18, 2011 3:25 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, July 26, 2016 3:41 AM
Points: 64, Visits: 1,163
mtassin (4/18/2011)
Make a table...
INSERT the daylight savings start and stop times plus the offset to use.
Now JOIN to this table

Of course if you operate in more than one country (or even in more than one state in Australia - don't know if everywhere in the US has the same DST rules), this table would get way more complicated where you have different places with different DST rules.... You'd have to add in a time zone name column too, which would then also need to get stored along with your datetimeoffset value in every table where you want to use the information - back to needing two columns to store your time data.

Having a 'DST' bit in the datetimeoffset type would be the best resolution. I would have thought they could add a bit quite easily - perhaps an extra bit of 'precision'.
Post #1095328
Posted Monday, April 18, 2011 9:17 PM

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: Sunday, July 24, 2016 7:01 PM
Points: 516, Visits: 1,803
Thanks for the article. My only suggestion is that I think you might have made a stronger point by using 'hour' for your DATEDIFF examples as timezone differences are [usually] measured in hours. But otherwise I think you did good by raising awareness of this feature.

It's worth mentioning that another 2008 feature, Data Collection, stored its results in UTC time. This threw me at first until I dug into the schema and then BOL'd datetimeoffset. I'd much rather have known about this earlier. (I was writing my own reports, btw. Not meaning to suggest that the Data Collection reports themselves are UTC time.)

As to daylight savings time being a consideration for functions, I fear this would be too unwieldy. There's a lot of different start-end dates for these, including many 'one-off' examples (ie: the Sydney 2000 Olympics garnered an extended DS period for just that year) and it would be a job in itself to maintain that system.

Post #1095393
Posted Monday, June 8, 2015 3:23 PM


Group: General Forum Members
Last Login: Yesterday @ 7:30 AM
Points: 7,902, Visits: 768
James A Skipwith (4/18/2011)
Good point Mark, Date would be better here as the time portion is irrelevant. I don't tend to store many dates like this but the Date data type would be preferred over Datetime.
Most of our dates (and we have plenty) don't care about time, such as the date range that someone is covered for a particular service. The few cases where we use datetime are for fields like the last time the record was touched or when the record was created.
Post #1692648
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse