Here is another function that you can provide the 2 pieces on information you have, Date and Time zone.
Convert to UTC
Nagesh CL
686
Reputation points
Hi All,
I have a sql table which contains the Date and the Timezone as below: -
Is there a way in SQL to convert the OrderDate to UTC timezone based on the TimeZone field?
Thanks.
Regards,
Nagesh CL
Accepted answer
1 additional answer
Sort by: Most helpful
-
Alberto Morillo 34,151 Reputation points MVP
2021-08-24T15:20:29.543+00:00 Please see the recommended options like AT TIME ZONE on this article.
Here you will find more examples of how to use AT TIME ZONE.
You may want to use a function like the one below:
CREATE FUNCTION [dbo].[fnGetLocalDate] (@DateToConvert DATETIMEOFFSET = NULL) RETURNS TABLE AS RETURN SELECT CONVERT(DATETIMEOFFSET, @DateToConvert AT TIME ZONE (SELECT Value FROM LookUp.Config WHERE Property = 'TimeZone')) AS LocalDate
Below an example of how to use it.
SELECT o.name, L.LocalDate FROM sys.objects o CROSS APPLY [dbo].[fnGetLocalDate](o.modify_date) AS L