Is there a function in SQL Server that will convert a DateTime saved as UTC time to the local time? The problem is that I have times saved as UTC times, and I used to calculate time zone offset as
select @tzoffset = datediff(mi,SYSDATETIMEOFFSET(),SYSDATETIME())
and adding that to my UTC times, which worked fine until daylight saving came. As that selects the current time zone offset, the calculation is invalid for pre-DST values.
As the dates are rendered in ASP.NET web form, I have worked around the issue by rendering the dates as TimeZoneInfo.ConvertTimeFromUtc((DateTime)Eval("maxtime"), TimeZoneInfo.Local), which works automagically.
Is there something similarly elegant in T-SQL?
It is not that simple. Read this http://blogs.msdn.com/b/bartd/archive/2009/03/31/the-death-of-datetime.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With