【问题标题】:How to convert timestamp to date in Presto?如何在 Presto 中将时间戳转换为日期?
【发布时间】:2018-04-03 20:29:33
【问题描述】:

我喜欢将我的时间戳列转换为日期和时间格式。我应该如何从 presto 编写查询?我的时间戳是UTC时间。非常感谢

Timestamp format"1506929478589"
After query convert it looks like "2016-10-25 21:04:08.436"

【问题讨论】:

    标签: sql presto trino


    【解决方案1】:

    您可以使用cast(col as date)date(col)timestamp 转换为date

    【讨论】:

      【解决方案2】:

      您可以使用 date_format 函数(此处的文档:https://prestodb.io/docs/current/functions/datetime.html

      这是一个例子:

      date_format(charges.created, '%Y-%m') as rev_month
      

      如果由于某种原因您在比较日期时不需要进行这样的转换,您可以执行以下操作

      where customers.created BETWEEN timestamp '2018-04-01 00:00:00.000' AND timestamp '2018-05-01 00:00:00.000' 
      

      【讨论】:

        猜你喜欢
        • 2020-11-16
        • 1970-01-01
        • 2018-10-07
        • 2019-08-24
        • 2012-04-10
        • 2016-11-26
        • 2019-04-03
        相关资源
        最近更新 更多