Click here to Skip to main content
15,889,096 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am trying to fetch the datetime records between two datetimes.

For Example,My Exam Date is 2013-08-01 00:00:00.000,Exam start time is 10 AM and Exam End Time is 7 Pm and Room Number is 123 which is availablein the tblTest

ExamTime,,,, ExamStarttTime ,,, ExamEndTime,,,,, RoomNo
2013-08-01 00:00:00.000,,, 2013-08-01 10:00:00.000,,,, 2013-08-01 19:00:00.000 ,,,, 201

If I pass the startdate as '2013-08-01 13:00:00.000' and enddate as '2013-08-01 14:00:00.000' in the select query .It should give the results.


SQL
select * from tblTest
   where ExamDate='8/1/2013'
    and(ExamStarttTime   between DateAdd(s,1,2013-08-01 13:00:00.000) and  DateAdd(s,-1,2013-08-01 14:00:00.000)
    or  (ExamEndTimebetween DateAdd(s,1,2013-08-01 13:00:00.000) and DateAdd(s,-1,2013-08-01 14:00:00.000;)))


Any Thoughts?
Posted

1 solution

Try this for the where clause
where ExamDate='8/1/2013' and
( 
ExamStarttTime between cast('2013-08-01 13:00:00.000' as datetime) and  cast('2013-08-01 14:00:00.000' as datetime)
or 
ExamEndTime between cast('2013-08-01 13:00:00.000' AS datetime) and cast('2013-08-01 14:00:00.000' as datetime)
)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900