gpt4 book ai didi

sql - 使用 datepart 函数提取日期,但以文本形式返回

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

我目前正在尝试找到一种从时间戳字段中提取月份的方法,设置为:yyyy-mm-dd,但以 3 个字母(二月)或完整月份(二月)返回值。目前正在按数字返回。

如有任何帮助,我们将不胜感激!

最佳答案

在 PostreSQL 中,有几种格式可供选择:

select 
to_char(current_timestamp, 'MONTH') as "MONTH",
to_char(current_timestamp, 'Month') as "Month",
to_char(current_timestamp, 'MON') as "MON",
to_char(current_timestamp, 'Mon') as "Mon",
to_char(current_timestamp, 'mon') as "mon",
to_char(current_timestamp, 'MM') as "MM";

结果:

MONTH    Month    MON      Mon      mon      MM
------- ------- ------- ------- ------- -------
JULY July JUL Jul jul 07

关于sql - 使用 datepart 函数提取日期,但以文本形式返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51448753/

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