I have the query like this:
SELECT table.a, table.b, table.c from Table table
How i can cast "table.b" to UTC time just adding CAST into the query?
SELECT
table.a,
**%CAST_TO_UTC_FUNCTION to table.b%**,
table.c
from Table table
I'm not able to cast it separately and declaring local variables.
You can write your query as follows:
This converts the values in column
b
to UTC, by adding to those values the tmie difference that currently exists between the local date (getDate()
) and the UTC date (getUtcDate()
).In order for the above query to work, the following must be true:
b
must be expressed in local timeI solved the problem by creating a temporary table that stores the date range and the current UTC offset. Here is the partial solution that works for US starting at year 2007, for regions that observe DST. It can be easily modified to for years before 2007. Please see the end of the solution for a sample usage