Wanted to do suppression of time in case of changing from/to daylight saving time.
I know for teradata there is function timezone_hour which will do the work easily.
However, I want to achieve same in BQ.
My requirements written below:
(Extract (timezone_hour from first_day)
Here in above statement I am assuming daylight saving has not started)
minus
Extract(timezone_hour from first_day +1 )In above statement daylight saving started. So at the same time there will forward/backward )
I need that exact number of hours between two days when the daylight started.
To effectively manage daylight saving time (DST) changes in BigQuery, follow these guidelines:
Store Timestamps in UTC:
TIMESTAMP
data type. This approach ensures uniformity in time representation, irrespective of DST changes.Apply Timezone Conversions During Data Retrieval:
DATETIME(timestamp_column, timezone_region)
for this conversion. This function automatically adjusts for DST in the specified timezone.Accurately Calculate Time Differences:
TIMESTAMP_DIFF
to compute the difference between timestamps. When both timestamps are converted to the same timezone, this function accurately accounts for any DST adjustments.Carefully Handle DST Transitions:
EXTRACT(HOUR FROM timestamp_column)
can be used to extract the hour component of a timestamp, it does not directly indicate a DST shift.Example Query:
SELECT TIMESTAMP_DIFF(
DATETIME(timestamp_column, "America/Los_Angeles"),
DATETIME(timestamp_column - INTERVAL 1 DAY, "America/Los_Angeles"),
HOUR
) AS hours_difference
FROM your_table
timestamp_column
is stored in UTC and converts it to a specific timezone, accounting for DST changes.Key Considerations:
TIMESTAMP_DIFF
for precise time difference calculations, especially around DST transitions.