In sql, i write a select statement for find the dates. i am here including the time also my select statement like this….
select * from test where
(
(
(DATEDIFF (day,@dat1,req_frmdate)=0 or DATEDIFF (day,@dat2,req_todate)=0)
and
(DATEDIFF (HOUR,@dat1,req_frmdate)=0 or DATEDIFF (HOUR,@dat2,req_todate)=0)
and
(DATEDIFF (MINUTE,@dat1,req_frmdate)=0 or DATEDIFF (MINUTE,@dat2,req_todate)=0)
)
or
(
( @dat1 between req_frmdate and req_todate) or
( @dat2 between req_frmdate and req_todate) or
(req_frmdate between @dat1 and @dat2) or
( req_todate between @dat1 and @dat2)
)
)
but when i pass the date some time it not considering the time.
is this query is right? when i am passing date for example @date1=’2013-02-20 09:00′
and @date2= ‘2013-02-20 12:00′ but there is no record in my databse on this date and time
there is a record in my database at req_frmdate=’2013-02-20 13:00’ and req_todate= ‘2013-02-20 16:00’
in the screen shot of my table, i have that record in my table, when i pass the two dates
like @date1=’2013-02-20 9:00′ and @date2=’2013-02-20 12:00′ the record is coming in my select statement, it should not come the date is different that is the my query.
Assuming you want that the records will display only IF both
REQ_FRMDATEandREQ_TODATEwill be between your two parameter’s dates, then you can useBETWEENClause: