从日期时间 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/