Find Date Range in C#

Rajnilari2015
Posted by Rajnilari2015 under C# category on | Points: 40 | Views : 74
Given a date like "8/16/2016", find the next 7 days range. The below code will do so

private static List<DateTime> GetDateRange(DateTime startDt)
{
List<DateTime> dtList = new List<DateTime>();
Enumerable
.Range(0, 7)
.ToList()
.ForEach(i => dtList.Add(startDt.AddDays(i)));
return dtList;
}


use like

var initialDate = Convert.ToDateTime("8/16/2016");
var dtRange = GetDateRange(initialDate);

Comments or Responses

Login to post response