c# - Linq Query with DateTime Compare is not Working as Expected -


at approximately 12/1/2014 9:40:12 pm, following code retrieves null value.

campaign camp = repo.campaigns                     .where(ca => ca.starttime <= datetime.now)                     .where(ca => ca.endtime >= datetime.now)                     .firstordefault(); 

when there campaign in database following values:

start time: 2014-11-30 00:00:00.000  end time: 2014-12-02 00:00:00.000 

i @ complete loss why occur.

try this:

campaign camp = repo.campaigns             .where(ca => ca.starttime.value.date <= datetime.now.date && ca.endtime.value.date >=datetime.now.date).firstordefault();  

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -