gpt4 book ai didi

sql - psql格式日期显示 "week W"

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

根据 Postgres 的数据类型格式化文档 https://www.postgresql.org/docs/9.1/static/functions-formatting.html

W 将允许它显示月中的星期 (1-5)。但是有没有办法让我转义字符串“week”中的“w”?

所以我可以指定 "\week W",并且它显示“第 1 周”、“第 2 周”等。

我知道之后可以进行字符串连接,但我想尽可能避免不必要的复杂性。

最佳答案

你可以使用这个:

SELECT TO_CHAR(current_timestamp, '"week" w');

您可以添加任何文本/字 rune 字,在您的格式模型中用双引号括起来。

Usage notes for date/time formatting:

......

Ordinary text is allowed in to_char templates and will be outputliterally. You can put a substring in double quotes to force it to beinterpreted as literal text even if it contains pattern key words. Forexample, in '"Hello Year "YYYY', the YYYY will be replaced by the yeardata, but the single Y in Year will not be. In to_date, to_number, andto_timestamp, double-quoted strings skip the number of inputcharacters contained in the string, e.g. "XX" skips two inputcharacters.

关于sql - psql格式日期显示 "week W",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50146788/

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