我想提取周数:
2015-52
从格式为的日期:
2015-12-27
我怎样才能在postgres中执行此操作?
我的周数是从星期一到星期日计算的。
要使用单个字符值获取年份和周数,请使用to_char()
select to_char(current_date, 'IYYY-IW');
IW
返回年份和周数,因为defined in the ISO standard和IYYY
返回相应的年份(可能是前一年)。
如果您需要年份和周数作为数字,请使用extract
select extract('isoyear' from current_date) as year,
extract('week' from current_date) as week;