gpt4 book ai didi

time - 从日期 postgres 中提取周数

转载 作者:行者123 更新时间:2023-12-03 14:44:27 25 4
gpt4 key购买 nike

我想提取周数为:

2015-52

从日期格式为:
2015-12-27

如何在 postgres 中执行此操作?

我的周数是从周一到周日计算的。

最佳答案

要以单个字符值获取年份和星期,请使用 to_char()

select to_char(current_date, 'IYYY-IW');
IW返回年份和周数为 defined in the ISO standardIYYY返回相应的年份(可能是前一年)。

如果您需要年份和周数作为数字,请使用 extract
select extract('isoyear' from current_date) as year, 
extract('week' from current_date) as week;

关于time - 从日期 postgres 中提取周数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34050103/

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