w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
how to find in SQL if the a time ( format:yymmdd hours:mins:secs) lies within a time frame?

Here is a where clause:

where (start_time < end_time and @VALUE between start_time
and end_time) or
      (start_time > end_time and @VALUE between end_time and start_time)

I assume you want a match, regardless of whether start_time is before or after end_time.

EDIT:

If you wanted this in a select, then use case:

select (case when (start_time < end_time and @VALUE between
start_time and end_time) or
                  (start_time > end_time and @VALUE between end_time and
start_time)
             then 1 else 0
        end) as Flag




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.