Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate 52 weeks from current date using Postgresql

Tags:

postgresql

How to generate 52 weeks from current date using postgresql

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

like image 688
PAVAN Avatar asked Aug 26 '26 16:08

PAVAN


1 Answers

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 ...

like image 140
Ali Avatar answered Aug 28 '26 06:08

Ali



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!