Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2006-08-09 : 09:35:00
|
| Jack writes "I have a startDate and endDate in my database. I want to determine if a supplied range (requestedStart and requestedEnd) conflicts. If I have startDate = 1/1/2006 08:00 AM and endDate = 1/1/2006 05:00 PM in the database how do I test if 1/1/2006 7:00 AM and 1/1/2006 06:00PM conflict?Thanks." |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-08-09 : 09:52:48
|
| Where yourDate not between StartDate and EndDateMadhivananFailing to plan is Planning to fail |
 |
|
|
mwjdavidson
Aged Yak Warrior
735 Posts |
Posted - 2006-08-09 : 09:53:40
|
If you're looking for any overlap, this should do it:SELECT mt.startDate, mt.endDateFROM MyTable AS mtWHERE @requestedEnd Between mt.startDate AND mt.endDate OR @requestedStart Between mt.startDate AND mt.endDate Mark |
 |
|
|
airjrdn
Starting Member
35 Posts |
Posted - 2006-08-09 : 09:56:00
|
| declare @requestedStart datetime, @requestedEnd datetimeselect @requestedStart = convert(datetime, '1/1/2006 7:00 AM'), @requestedEnd = convert(datetime, '1/1/2006 6:00 AM')if datediff(s, @requestedStart, @requestedEnd) < 0 select 'conflict'else select 'ok' |
 |
|
|
|
|
|