Sunday, February 2, 2014

How to handle SQL code for Daylight Savings for MST Time zone

Hi Abdul,


You should use this data type for all columns for which timezones or daylight savings is an issue. If in doubt it is safe to use datetimeoffset(0) for all columns which contain date time. However if your information source does not contain timezone information the offset will 0:00, which won't do you any good. The datetimeoffset(0) date type allows you to store the offset, but it will not magically create this information.


If you use the GETDATE() function to obtain the current date and time, you can replace it with the SYSDATETIMEOFFSET() function which includes the offset. See the example


SELECT GETDATE(), CAST(GETDATE() AS datetimeoffset(0)), CAST(GETUTCDATE() AS datetimeoffset(0)), CAST(SYSDATETIMEOFFSET() AS datetimeoffset(0));


Please note that the offset may or may not show up next to the date time in the report. This might be something unexpected for the end user. However there are some ways to format your date in the end report. Be sure to discus with your client how date time should be formatted in the report.


Hope this helps.


No comments:

Post a Comment