Home > SQL Script > Detect Overlapping DateTime

Detect Overlapping DateTime

declare @starttime as datetime
declare @endtime as datetime
declare @inputstarttime as datetime
declare @inputendtime as datetime

set @starttime=’2007-04-01 00:00:00′
set @endtime=’2007-04-10 00:00:00′
set @inputstarttime=’2007-03-10 00:00:00′
set @inputendtime=’2007-04-01 00:00:00′

select    
    case
        when @inputstarttime>@starttime and @inputstarttime<@endtime
            Then ‘Yes’
        when @inputendtime>@starttime and @inputendtime<@endtime
            Then ‘Yes’
        when @inputstarttime <= @starttime AND @inputendtime >= @endtime
            Then ‘Yes’
        Else
            ‘No’
    end as [Overlapping?]

Advertisements
Categories: SQL Script
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: