EF 4 in C#.
I have my query, at the moment I'm able to filter the result by the current Date (just date not considering TIME).
I need to filter the result FROM the last two days TO the current Date (no idea how to do it).
I tried in my query currenteDate - 2
but without success.
Could you please give me an example? Thanks for your time on this.
DateTime currenteDate = DateTime.UtcNow.Date;
var contents = from cnt in context.CmsContents
where cnt.IsPublished == true & cnt.IsDeleted == false & cnt.Date == currenteDate
orderby cnt.ContentId descending
select new { cnt.ContentId, cnt.Title, cnt.TitleUrl, cnt.Date, cnt.TypeContent };
For changing current date you need use currenteDate.AddDays(-2)
. And use >=
instead of ==
to get all records from 2 days before and till the last record
DateTime currenteDate = DateTime.UtcNow.Date.AddDays(-2);
var contents = from cnt in context.CmsContents
where cnt.IsPublished == true & cnt.IsDeleted == false & cnt.Date >= currenteDate
orderby cnt.ContentId descending
select new { cnt.ContentId, cnt.Title, cnt.TitleUrl, cnt.Date, cnt.TypeContent };
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With