在sql中它看起来像这样:
select to_char(d,'WW') as Week
, to_char(d,'YYYY') as Year
, to_char(d,'DD') as "Day of Friday"
, d
from (
select (level-1)*7 + to_date('02/01/2015','DD/MM/YYYY') d
from dual
connect by level <= 53*5);
但我需要一个Postgres脚本......
答案 0 :(得分:0)
你试过extract(year from <your date field>)
吗?看date-time functions
答案 1 :(得分:0)
Postgres日期时间掩码几乎相同。在你的情况下,我猜他们是平等的:
select to_char(d,'WW') as Week
, to_char(d,'YYYY') as Year
, to_char(d,'DD') as "Day of Friday"
, d
from to_date('02/01/2015','DD/MM/YYYY') d
给出:
01; 2015; 12; 2015-01-12
除非预计周不是第一个和'星期五'和#34;不是一个月的一天......
答案 2 :(得分:0)
感谢您的回复
这就是我想要的:
SELECT
extract('week' from d) as "Week"
,extract('year' from d) as "Year"
,extract('day' from d) as "Friday Number"
FROM generate_series('2015-01-02'::date, '2015-12-31'::date, '1 week'::interval) d