简体   繁体   English

SQL 下周一在 Presto

[英]SQL to get next monday in Presto

I need to get the date for next Monday irrespective of which day the sql is executed.无论执行 sql 的哪一天,我都需要获取下周一的日期。

I think the logic 7 - day_of_week(current_date)%7 + 1 would work, but then how to get the date.我认为逻辑7 - day_of_week(current_date)%7 + 1会起作用,但是如何获取日期。

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!!我将不胜感激任何帮助!

You can use date_trunc to get the Monday of the current week and add 7 days to it:您可以使用date_trunc获取本周的星期一并添加 7 天:

presto> select date_trunc('week', current_date) + interval '7' day;

   _col0
------------
 2019-11-18
(1 row)

You could do:你可以这样做:

date_add(day, 8 - extract(day_of_week from current_date), current_date)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM