Find Date Range in C#

Posted by Rajnilari2015 under C# category on | Points: 40 | Views : 51
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>();
.Range(0, 7)
.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