gpt4 book ai didi

postgresql - 如何在 Postgresql 中获取字符串中的当前月份和年份

转载 作者:行者123 更新时间:2023-11-29 12:49:24 28 4
gpt4 key购买 nike

我想以字符串格式显示日期作为当前月份名称(字符串)和年份(例如 -> 2019 年 9 月)。如何在 PostgreSQL 中为此编写查询?

我尝试了这个查询:

select 
date(date_trunc('month', current_date));

但它只给我当前月份的开始日期。

最佳答案

尝试 to_char() 并添加年份 formatter像这样的字符串:

SELECT to_char(current_date, 'MONTH YYYY')

这将返回:

SEPTEMBER 2019

这是一个sqlfiddle

关于postgresql - 如何在 Postgresql 中获取字符串中的当前月份和年份,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57890243/

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