【发布时间】:2022-01-06 15:06:36
【问题描述】:
文档:https://prestodb.io/docs/current/functions/datetime.html
我有纪元时间戳,我想从中提取一年中的一周,例如 2021-32、2020-50、2021-02 等等。
SELECT concat(date_format(from_unixtime((CAST(my_timestamp AS BIGINT) + 19800000)/1000), '%Y'),
'-' ,
date_format(from_unixtime((CAST(my_timestamp AS BIGINT) + 19800000)/1000), '%v'))
AS week
但是我得到了一些错误的值,例如:
week = 2021-53 对应于 2021 年 1 月 1 日或 2021 年 1 月 2 日的 Epoch-Time。我知道这里发生了同步问题,但这绝对不是我想要的 - 我如何抵消这样一周的第一天1 从年初开始。
【问题讨论】:
-
如果 53 看起来太高,那么您可以从第 00 周开始吗?
date_format(date('2021-01-03'), '%Y-%u')(星期日)返回 2021-00 -
@LukStorms 奇怪的是,我收到一个错误,即不支持 %u 作为一种格式,即使我看到它在文档中列出。
INVALID_FUNCTION_ARGUMENT: %u not supported in date format string。我在 AWS Athena 上运行查询,它在下面使用 Presto SQL 引擎。 -
我的错。文档中有警告。
The following specifiers are not currently supported: %D %U %u %V %w %X哦,好吧,可能没有多少人需要它。