Return date/times outside of a date/time range
Hi guys,
As if the title isn't confusing enough! I'm new here so hopefully someone can help me out and it certainly looks like a good community, so I'll endeavour to help out where I can too!
I'm stumped by something I've been asked to do recently and was hoping someone can point me in the right direction.
Basically my setup can be simplified into the following:
1 x Table which contains an auto-incrementing ID and 2 x Date/Time fields.
So an example of data stored in this could be:
ID | DateTime In | DateTime Out
1 | 10/07/2012 09:00 | 10/07/2012 10:00
2 | 10/08/2012 12:00 | 10/07/2012 13:00
Basically, I need to feed into this query 2 date times such as 10/07/2012 08:30 and 10/07/2012 13:30.
What I would like it to do is then search through my table and output times (each hour/half an hour) which it would view as 'available'.
For example, I feed in 10/07/2012 08:30 and 10/07/2012 13:30 and I would like then like it to output something like the following:
10/07/2012 08:30 - 10/07/2012 09:00
10/07/2012 10:00 - 10/07/2012 12:00
10/07/2012 13:00 - 10/07/2012 13:30
My question is, is this entirely possible using only SQL? Coming from a programmer perspective, this seems hard enough to do in code so I'm crossing my fingers that SQL can help me out here.
Does anyone have any suggestions as to the best way to tackle this?
Thanks in advance,
Adam