In Postgres, given week X in year Y, how to get the Monday date of that week/year?
Example:
monday_of(1, 2020) -> '2020-01-30'
monday_of(33, 2020) -> '2020-08-10'
monday_of(53, 2020) -> '2020-12-28'
monday_of(54, 2020) -> '' (year does not have 54 weeks)
You can use date arithmetics. Assuming that
yr
andwk
are the year and week parameters:Note, however, that this does not detect out of range weeks (but you can easily add conditional logic to handle that).
Demo on DB Fiddle: