Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get week start date from week number in postgresql?

Tags:

sql

postgresql

I have all week numbers from 20161 to 201640. I want to know what is the start date and end date of week 31.

How can I write query in postgresql to get that?

like image 852
YOBOX Avatar asked Oct 17 '16 14:10

YOBOX


1 Answers

To get the start date, simply convert the week number to a date using to_date()

If you are using ISO week numbers use:

select to_date('201643', 'iyyyiw');

Otherwise use:

select to_date('201643', 'yyyyww');

To get the end date, just add 7 to resulting date: to_date('201643', 'iyyyiw') + 7

like image 92
a_horse_with_no_name Avatar answered Oct 20 '22 00:10

a_horse_with_no_name