'SQL to get next monday in Presto
I need to get the date for next Monday irrespective of which day the sql is executed.
I think the logic 7 - day_of_week(current_date)%7 + 1 would work, but then how to get the date.
select current_date;
_col0
1 2019-11-16
select (7 - day_of_week(current_date)%7+1)
_col0
1 2
Or is there any other better way to do the same.
I will appreciate any help!!
Solution 1:[1]
You could do:
date_add(day, 8 - extract(day_of_week from current_date), current_date)
Solution 2:[2]
You can use date_trunc to get the Monday of the current week and add 7 days to it:
presto> select date_trunc('week', current_date) + interval '7' day;
_col0
------------
2019-11-18
(1 row)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 |
