Skip to content
Advertisement

In SQL query (BigQuery) How get all rows where CreatedDatetime is Today in Moscow tz from column with UTC tz?

I have a table with CreatedDatetime column. This column is in UTC timezone (Values look like this:
2020-12-20 01:00:00 UTC). I need to get all rows where date is Today, but in Europe/Moscow timezone, which is +3 hours. Instead

SELECT TIMESTAMP_ADD(TIMESTAMP_TRUNC(CreatedDatetime, HOUR), INTERVAL 3 HOUR) AS date_hour_msk
FROM table_name
WHERE DATE(CreatedDatetime) = CURRENT_DATE('Etc/GMT')

I need something like this:

WHERE CreatedDatetime >= 'yesterday 21:00:00' AND Created <= 'today 21:00:00'.

Advertisement

Answer

In Bigquery, you can convert an UTC timestamp to a local timezone like this:

TIMESTAMP(CreatedDatetime, 'Europe/Moscow')

Presumably, you want something like:

select TIMESTAMP(CreatedDatetime, 'Europe/Moscow') as local_time
from table_name
where DATE(CreatedDatetime, 'Europe/Moscow') = CURRENT_DATE('Europe/Moscow')
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement