如何在 Presto 中将时间戳转换为日期?

How to convert timestamp to date in Presto?

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

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

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

您可以使用 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'