michael1174
asked on
linq to sql not between
I have the following where clausing in sql, how do i write the comparable in linq?
where CONVERT(DATE, GETDATE()) not between CheckInDate and CheckOutDate
I'm trying to query the non active records in my table, which means today's date will not fall in between the check in and check out dates.
Thanks
where CONVERT(DATE, GETDATE()) not between CheckInDate and CheckOutDate
I'm trying to query the non active records in my table, which means today's date will not fall in between the check in and check out dates.
Thanks
ASKER
Hi thanks I already have that for active records, I need to get NOT active records which is a NOT between.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
one more question, it worked for one of my queries, but my other query, which first i am getting it through a SP:
var query = (get from sp).toList();
return query.Where(m => (DateTime.Today >= m.StartDate) &&
(m.EndDate <= DateTime.Today));
it doesn't seem to be filtering out the records, see any problems?
var query = (get from sp).toList();
return query.Where(m => (DateTime.Today >= m.StartDate) &&
(m.EndDate <= DateTime.Today));
it doesn't seem to be filtering out the records, see any problems?
this query returns all records between StartDate and EndDate (exclusive compare) , is that what u want?
btw, you used DateTime.Today and not DateTime.Now to compare which returns the current date with time equals to 12:00:00 AM.
for example:
DateTime.Today -> {1/31/2013 12:00:00 AM}
DateTime.Now -> {1/31/2013 14:45:00 PM}
btw, you used DateTime.Today and not DateTime.Now to compare which returns the current date with time equals to 12:00:00 AM.
for example:
DateTime.Today -> {1/31/2013 12:00:00 AM}
DateTime.Now -> {1/31/2013 14:45:00 PM}
ASKER
yes, that is what I want but for some reason my query result is wrong. It doesn't seem like the filter was applied. I'm first calling a sp, and then applying that where. The method returns a ienumerable and the result is bound to a grid.
thanks for explaination on the date today vs date now.
thanks for explaination on the date today vs date now.
well the query is simple and straight forward.
debug the StartDate and EndDate and see if it falls within the query range.
debug the StartDate and EndDate and see if it falls within the query range.
Open in new window