How to generate 52 weeks from current date using Postgresql

后端 未结 1 456
甜味超标
甜味超标 2021-01-22 15:17

How to generate 52 weeks from current date using postgresql

for example: from current_date(i.e todays date) to 52 weeks .

1条回答
  •  悲哀的现实
    2021-01-22 15:28

    You can use generate_series which allows you to define range (start, stop) as well as the step interval like: generate_series(startDate, endDate, stepBy) so depending on output format you are after you could do something like:

    SELECT generate_series( current_date, current_date + interval '52 weeks', interval '1 week' ) weeks;

    which would generate something like this:

    weeks 2017-05-24 00:00:00 2017-05-31 00:00:00 2017-06-07 00:00:00 ...

    0 讨论(0)
提交回复
热议问题