How can I find the date of the first day of the n
th week of the year? For example, all of the following queries:
SELECT DATE_PART('WEEK', '2019-07-22 01:12:07'::timestamp);
SELECT DATE_PART('WEEK', '2019-07-23 01:12:07'::timestamp);
SELECT DATE_PART('WEEK', '2019-07-24 01:12:07'::timestamp);
give 30, because these three dates are in the 30th week of 2019.
My question is how I can do the opposite of this. Weeks start on Mondays in my version of SQL (not a problem if your starts on Sunday - I can do the adjustment) therefore the first day of week 30 is 2019-07-22 (today, which is Monday). How can I enter the week number, 30, and get the first day of that week, i.e. 2019-07-22 (or 07-21, if the first day of a week is a Sunday in your SQL)