简体   繁体   中英

How to get values between two date time in Asp.Net?

I would like to get values between two Datetime which values between one day ago and today but I don't know how I do it.

_db.Contact.Where(p => DateTime.Now.AddDays(-1) < p.Date <= DateTime.Now && p.Email == entity.Email).ToList()

Close, but you can't chain conditions like that in C#. You need to make two separate conditions for the < and the <= :

_db.Contact.Where(p => DateTime.Now.AddDays(-1) <  p.Date 
    && p.Date <= DateTime.Now 
    && p.Email == entity.Email)
.ToList()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM