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

问题描述 投票:2回答:2

我喜欢将时间戳列转换为日期和时间格式。我该怎么写presto的查询?我的时间戳是UTC时间。非常感谢你

Timestamp format"1506929478589"
After query convert it looks like "2016-10-25 21:04:08.436"
sql presto
2个回答
4
投票

你可以用timestampdatecast(col as date)转换成date(col)


0
投票

您可以使用date_format函数(docs: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' 
© www.soinside.com 2019 - 2024. All rights reserved.