【问题标题】:How to get difference(in hours) between two timestamp in bigquery如何获得bigquery中两个时间戳之间的差异(以小时为单位)
【发布时间】:2016-07-21 11:08:11
【问题描述】:

我想在 google bigquery 中获取两个时间戳之间的差异(以小时为单位); 请帮忙。

【问题讨论】:

    标签: google-bigquery


    【解决方案1】:

    使用标准 SQL

    TIMESTAMP_DIFF(timestamp_expression1, timestamp_expression2, HOUR)
    

    https://cloud.google.com/bigquery/docs/reference/standard-sql/functions-and-operators#timestamp_diff

    【讨论】:

      【解决方案2】:

      在下面运行,你会看到一个使用的想法

      SELECT 
        CURRENT_TIMESTAMP() AS timestamp_now, 
        TIMESTAMP(CURRENT_DATE()) AS timestamp_start_of_day, 
        FLOOR((CURRENT_TIMESTAMP() - TIMESTAMP(CURRENT_DATE()))/1000000/3600) AS diff_in_hours
      

      查看更多 Date and time functionsMathematical functions

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-05-14
        • 1970-01-01
        • 2014-05-04
        • 2020-06-08
        • 2021-07-31
        相关资源
        最近更新 更多