Click here to Skip to main content
15,894,646 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi All,

I have a table having fields as startdate as datetime and endate as datetime and has records . Now my problem is that I have to check that an input date lies between startdate and endate. and that is equal to startdate or endate.

data is like

Employee name , startdate , endate
MSIL
rehan ahmad 2011-02-02 00:00:00.000 2011-02-03 00:00:00.000
Mohd Wasif  2011-01-28 00:00:00.000 2011-01-28 00:00:00.000
Mohd Wasif  2011-03-09 00:00:00.000 2011-03-09 00:00:00.000
Mohd Wasif  2011-05-02 00:00:00.000 2011-05-02 00:00:00.000
rehan ahmad 2011-02-23 00:00:00.000 2011-02-26 00:00:00.000
rehan ahmad 2011-03-04 00:00:00.000 2011-03-05 00:00:00.000
rehan ahmad 2011-03-07 00:00:00.000 2011-03-08 00:00:00.000
Mohd Wasif  2011-03-07 00:00:00.000 2011-03-08 00:00:00.000
Mohd Wasif  2011-03-04 00:00:00.000 2011-03-04 00:00:00.000
Mohd Wasif  2011-02-04 00:00:00.000 2011-02-04 00:00:00.000


Please let me know how to fetch data.

thanks in advance
muhammad Wasif

UPDATE:
OP posted a comment that it was solved.
Posted
Updated 1-Feb-11 22:29pm
v2
Comments
Mohd Wasif 2-Feb-11 2:08am    
Solved

SQL
select * from your_table where '01/13/2011' between startdate and enddate

OR

select * from your_table where '01/13/2011' between CONVERT(VARCHAR(10), startdate, 101) AND CONVERT(VARCHAR(10), enddate, 101)
 
Share this answer
 
Comments
Mohd Wasif 2-Feb-11 2:08am    
Thanks
This should do it -
select * from mytable where startdate <= @myDate and enddate >= @mydate
 
Share this answer
 
v2

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