Reputation: 1779
I know how to extract a DOW from a date. eg SELECT EXTRACT(DOW FROM '2018-04-23'::date)
But how can I do the inverse? How can I take a series of DOW and convert them into the next date for a given week? (relative to the current week).
+-----+---------+
| id | the_dow |
+-----+----------
| 358 | 1 |
| 359 | 2 |
| 360 | 5 |
| 361 | 2 |
| 362 | 3 |
+-----+---------+
Upvotes: 1
Views: 52
Reputation:
Just add that number to the start of the week:
date_trunc('week', current_date)::date + the_dow
As far as I know date_trunc()
uses the ISO definition of the week, so the first day will be Monday. Using the isodow
for the extract and the subtracting 1
from that value would be easier.
Upvotes: 1