英文:
how to convert start date parameter to microsecond in custom query?
问题
I try to use custom query in Google Looker Studio as the data source. and here is the custom SQL to fetch data from my BigQuery
WITH analytics_data AS (
SELECT user_pseudo_id,
UNIX_MICROS(TIMESTAMP("2023-03-10 00:00:00", "+7:00")) AS start_day,
3600*1000*1000*24*7 AS one_week_micros
FROM `project.analytics_297774888.events_*`
WHERE _table_suffix BETWEEN @DS_START_DATE AND @DS_END_DATE
)
as you can see I enable date range parameters, so I use @DS_START_DATE
and @DS_END_DATE
. my problem is in this one line
UNIX_MICROS(TIMESTAMP("2023-03-10 00:00:00", "+7:00")) AS start_day
currently it is hardcoded string ("2023-03-10 00:00:00"). I want to replace the date string with @DS_START_DATE
. If I change the code to be like one below, I will have error
UNIX_MICROS(TIMESTAMP(@DS_START_DATE, "+7:00")) AS start_day
I am trying to get Unix Microsecond (number of microseconds since 1970-01-01) of date @DS_START_DATE
at 00:00:00 in timezone UTC + 7
how to do that?
英文:
I try to use custom query in Google Looker Studio as the data source. and here is the custom SQL to fetch data from my BigQuery
WITH analytics_data AS (
SELECT user_pseudo_id,
UNIX_MICROS(TIMESTAMP("2023-03-10 00:00:00", "+7:00")) AS start_day,
3600*1000*1000*24*7 AS one_week_micros
FROM `project.analytics_297774888.events_*`
WHERE _table_suffix BETWEEN @DS_START_DATE AND @DS_END_DATE
)
as you can see I enable date range parameters, so I use @DS_START_DATE
and @DS_END_DATE
. my problem is in this one line
UNIX_MICROS(TIMESTAMP("2023-03-10 00:00:00", "+7:00")) AS start_day
currently it is hardcoded string ("2023-03-10 00:00:00"
). I want to replace the date string with @DS_START_DATE
. If I change the code to be like one below, I will have error
UNIX_MICROS(TIMESTAMP(@DS_START_DATE, "+7:00")) AS start_day
I am trying to get Unix Microsecond (number of microseconds since 1970-01-01) of date @DS_START_DATE
at 00:00:00 in timezone UTC + 7
how to do that?
答案1
得分: 1
自 @DS_START_DATE
和 @DS_END_DATE
的格式为 YYYYmmdd
,您可以使用 PARSE_TIMESTAMP
来解析它,如下所示,同时指定时区。
UNIX_MICROS(PARSE_TIMESTAMP('%Y%m%d', @DS_START_DATE, '+7:00'))
英文:
Since @DS_START_DATE
and @DS_END_DATE
has a shape of YYYYmmdd
, you can parse it using PARSE_TIMESTAMP
like below along with timezone.
UNIX_MICROS(PARSE_TIMESTAMP('%Y%m%d', @DS_START_DATE, '+7:00'))
答案2
得分: 0
以下是翻译好的代码部分:
尝试这个:
WITH analytics_data AS (
SELECT user_pseudo_id,
UNIX_MICROS(TIMESTAMP(CONCAT(@DS_START_DATE, " 00:00:00"), "+7:00") AS start_day,
3600*1000*1000*24*7 AS one_week_micros
FROM `project.analytics_297774888.events_*`
WHERE _table_suffix BETWEEN @DS_START_DATE AND @DS_END_DATE
)
英文:
Try this:
WITH analytics_data AS (
SELECT user_pseudo_id,
UNIX_MICROS(TIMESTAMP(CONCAT(@DS_START_DATE, " 00:00:00"), "+7:00")) AS start_day,
3600*1000*1000*24*7 AS one_week_micros
FROM `project.analytics_297774888.events_*`
WHERE _table_suffix BETWEEN @DS_START_DATE AND @DS_END_DATE
)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论