LoginSignup
1
2

More than 5 years have passed since last update.

prestoの気持ち 時間関係(Date and Time Functions and Operators)

Posted at

型変換

string -> timestamp

parse_datetime(string, format)  timestamp with time zone

timestamp -> varchar

format_datetime(timestamp, format)  varchar

時間の加減計算

timestamp同士の引き算

-- 引き算
date_diff(unit, timestamp1, timestamp2)  bigint

unitの例

second
minute
hour
day
week
month
year

使用例
dtがユーザー登録日だとすると、以下のコードで登録日からの経過日数になる

date_diff('day',  DATE_PARSE(dt, '%Y-%m-%d %H:%i:%s.000') + interval '9' hour, current_timestamp + interval '9' hour)
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2