1
need to make a filter with Line in an entity, this filter should bring all events for the next 90 days.
Today’s example: 11/01/2017 until 11/04/2017 (90 days)
_con.SiteContexto.AsNoTracking()
.Where(e => e.Data....).ToList();
1
need to make a filter with Line in an entity, this filter should bring all events for the next 90 days.
Today’s example: 11/01/2017 until 11/04/2017 (90 days)
_con.SiteContexto.AsNoTracking()
.Where(e => e.Data....).ToList();
6
You can do it like this:
DateTime filtro = DateTime.Now.AddDays(90);
var r = db.SiteContexto.Where(x => x.DataEnvio < filtro && x.DataEnvio > DateTime.Now).ToList();
Get all records who have the date greater than now and less than (now + 90 days)
UPDATING:
Improving the explanation a little:
Datetime.Now will return the current date and time. To mount with the last minute of the day and not the first you can do this:
DateTime filtro = DateTime.Now.Date.AddDays(90)
.AddHours(23)
.AddMinutes(59)
.AddSeconds(59)
.AddMilliseconds(999);
With that the < filtro will recover all of the last day too.
You can vary with this, how to add 91 days (.AddDays(91)) instead of adding as suggested above.
Thanks for the comment jbueno.
3
Get all events with date equal to or greater than today and less than or equal to (today + 90 days).
It is important to use the function TrucateTime() to disregard the hours.
_con.SiteContexto
.Where(e => DbFunctions.TrucateTime(e.Data) >= DbFunctions.TrucateTime(DateTime.Now) &&
DbFunctions.TruncateTime(e.Data) <= DbFunctions.TrucateTime(DateTime.Now.AddDays(90))
.ToList();
If you’re using an Entity Framework version earlier than 6, use EntityFunctions instead of DbFunctions
Browser other questions tagged c# asp.net-mvc asp.net-mvc-5 linq filter
You are not signed in. Login or sign up in order to post.
Watch out for the hours!
– Jéf Bueno
Thanks for the comment, I improved the response a little!
– Ricardo
DateTime.Nowwill return the current time and not with "zero hours".– Jéf Bueno