Question: We have a configuration table as shown below that stores the start time and the duration.
If the start time is 9:20 pm (3rd one ) add the duration then the time becomes 9:35. 
I have to find out if the current time is in between any of the values.
I have to return the output based on the start\_time and duration. i.e current time should be between start\_time and the start\_time + duration. (between 09:20 and and 09:35)
Can you please help me with the sql query or is it better if we go with sql function?

```
Start_time, duration(minutes)   output

1108                 5            2

1054                100           5

2120                15            8

```

Answer: 
I'm not a fan of storing dates and times in `VARCHAR2` columns. `START_TIME` should really be a `DATE` or a `TIMESTAMP` column.

That said, you can do something like

```
 with x as (
   select '1108' start_time, 5 duration, 2 output from dual
   union all
   select '1054', 100, 5 from dual
   union all
   select '2120', 15, 8 from dual
 )
 select *
   from (
     select to_date(
               to_char(sysdate,'YYYY-MM-DD') || ' ' ||
                 start_time,
               'YYYY-MM-DD HH24MI' ) start_date,
            to_date(
               to_char(sysdate,'YYYY-MM-DD') || ' ' ||
                 start_time,
               'YYYY-MM-DD HH24MI' ) + duration/24/60 end_date
   from x)
  where sysdate between start_date and end_date

```
The following selects all rows where sysdate is within the Start\_Time and Start\_Time + duration (EDITed as per comment from OP):

```
SELECT (TRUNC ( SYSDATE ) + TO_NUMBER ( SUBSTR ( Start_Time, 0, 2 ) ) / 24.0 + TO_NUMBER ( SUBSTR ( Start_Time, 3 ) ) / (24.0 * 60.0))  start_date, (TRUNC ( SYSDATE ) + TO_NUMBER ( SUBSTR ( Start_Time, 0, 2 ) ) / 24.0 + TO_NUMBER ( SUBSTR ( Start_Time, 3 ) ) / (24.0 * 60.0) + TO_NUMBER (duration))  end_date FROM configtable;

```