在 BigQuery 中将 UNIX 时间 (INT) 转换为时间戳

问题描述 投票:0回答:4

我在 BigQuery 表中有一个列“date_time”,其中包含 unix 时间戳值,例如“1569888224”。问题是这些值是整数数据类型,而不是时间戳数据类型,所以我似乎没有一种简单的方法将它们转换为人类可读的日期/时间。有人有在 BigQuery 中将这些整数转换为日期时间值的好方法吗?

谢谢!

google-bigquery unix-timestamp epoch datetime-conversion
4个回答
18
投票

这可以通过使用 BigQuery 的 TIMESTAMP_SECONDS 函数来解决 - https://cloud.google.com/bigquery/docs/reference/standard-sql/timestamp_functions#format_timestamp

select TIMESTAMP_SECONDS(date_time) from table;

8
投票

任何尝试在 BigQuery 中转换 Firebase event_timestamp 的人的快捷方式:

SELECT
TIMESTAMP_SECONDS(CAST(CAST(event_timestamp as INT64)/1000000 as INT64)) as converted,
event_timestamp,
event_date
FROM [table] LIMIT 10

4
投票

取决于您的列值,但通常 int64 值由 16 位数字组成,例如;

- event_timestamp
- user_first_touch_timestamp
- etc...

您应该使用以下功能;

TIMESTAMP_MICROS(event_timestamp) event_datetime    
TIMESTAMP_MICROS(user_first_touch_timestamp) user_first_touch

如果不是16位数字,您可以尝试其他适合您的功能;

TIMESTAMP_SECONDS
TIMESTAMP_MILLIS

0
投票

使用您喜欢的时间戳,这里我使用了IST(印度标准时间)

选择 TIMESTAMP_SECONDS(Column_Name) AS unix_timestamp, CONCAT(FORMAT_TIMESTAMP('%Y-%m-%d %H:%M:%S', TIMESTAMP_SECONDS(Column_Name), '亚洲/加尔各答'), ' IST') AS IST_timestamp 从

bigquery-public-data.google_analytics_sample.ga_sessions_*

© www.soinside.com 2019 - 2024. All rights reserved.