Oracle sql to find the next monday from the stop time in the query

52 views Asked by At

If the Start_time is 01/06/2023 and 01/19/2023 - Stop_Time in the BELOW query,

select distinct start_time, stop_time
hwm_tm_rec_grp_sum
and sysdate between start_time and stop_time

I need to create another query that returns the 01/23/2023 which will be the next monday from the stop_time in the above query.

2

There are 2 answers

2
OldProgrammer On
select distinct start_time, stop_time, next_day(stop_time,'MONDAY')
...etc...
0
MT0 On

You can use TRUNC(date_value, 'IW') to truncate to midnight Monday of that week and then add 7 days:

SELECT DISTINCT
       start_time,
       stop_time,
       TRUNC(stop_time, 'IW') + 7 AS next_monday
...

This will work regardless of the session language.