I have a start Date : 01-01-2019 and End-Date 31-12-2019
I need to get all possible periods between those dates, but by interval.
Interval can be 180, 90, 45, 15 , 7 and 1 days.
So if I select 180 days return should be a list with those periods:
01/01/2019 - 30/06/2019 (First period of generated list )
01/07/2019 - 31/12/2019 (Second period of generated list )
It is almost like Generate list of list for start and end date of week from date range But I need do this in C#
How to find a list of Dates from a Start-Date and End-Date Is not quite What I need. But is close.
DateTime startDate = DateTime.Parse("01/01/2019");
DateTime endDate = DateTime.Parse("31/12/2019");
dayInterval = 45;
startDate = startDate.AddDays(dayInterval);
endDate = endDate.AddDays(-dayInterval);
I also tried:
var startDate = new DateTime(2019, 1, 1);
var endDate = new DateTime(2019, 12, 31);
int days = 45;
List<DateTime> range = Enumerable.Range(0, days)
.Select(i => startDate.AddDays(i))
.ToList();