'How to get past week dates from a list of dates in C#?
In My DB I have a dates like this:
01-03-2022 00:00:00
07-03-2022 00:00:00
05-03-2022 00:00:00
012-03-2022 00:00:00
013-03-2022 00:00:00
014-03-2022 00:00:00
after every week on Monday, I need past 1 week dates to be fetched
I am iterating through dates like this:
foreach(var item in model.dates)
{
// item.Date has all dates
// I don't know how to get dates here
}
I want to fetch only those dates, How can I do that?
Solution 1:[1]
if (DateTime.Today.DayOfWeek == DayOfWeek.Monday)
{
DateTime weekStart = DateTime.Today.AddDays(-7);
DateTime weekEnd = DateTime.Today.AddDays(-1);
var result = model.Dates.Where(x => weekStart <= x && weekEnd >= x);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | fubo |
