gpt4 book ai didi

mysql - Presto 或 Postgres 中的 mysql date_format() 等价物是什么?

转载 作者:行者123 更新时间:2023-12-04 15:10:52 24 4
gpt4 key购买 nike

从日期时间 2018-12-12 10:10:10 到只有年月我通常会在 MySQL8.0 中这样做

date_format('2018-12-12 10:10:10', '%Y-%m')

输出 2018-12

我如何在 Presto 或 Postgres 中执行此操作?

我可以用

concat(cast(year('2018-12-12 10:10:10') as varchar),'-',cast(month('2018-12-12 10:10:10')作为 varchar)) 作为 year_month

但是看起来很麻烦。

最佳答案

在 Postgres 上,我们可以在这里使用 TO_CHAR:

SELECT TO_CHAR('2018-12-12 10:10:10'::timestamp, 'YYYY-MM') AS dt;
-- outputs 2018-12

关于mysql - Presto 或 Postgres 中的 mysql date_format() 等价物是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65227682/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com