⏱️

BigQueryでtimestampの差分を出す

2022/04/07に公開

備忘録です。

公式ドキュメント
https://cloud.google.com/bigquery/docs/reference/standard-sql/timestamp_functions?hl=ja#timestamp_diff

select 
	timestamp_diff(ts_end, ts_start, day) as diff_day,
	timestamp_diff(ts_end, ts_start, hour) as diff_hour,
	timestamp_diff(ts_end, ts_start, minute) as diff_minute,
	timestamp_diff(ts_end, ts_start, minute) as diff_second,
	timestamp_diff(ts_end, ts_start, millisecond) as diff_ms,
from
  (
  select
	  timestamp "2022-01-01 00:00:00+00" as ts_start,
	  current_timestamp() as ts_end
  )
;

Discussion