Reputation: 1105
I have two datepickers
string dateFIRST = (dateSTART.Value.ToString("yyMMdd"));
string dateLAST = (dateEND.Value.ToString("yyMMdd"));
How can I use a foreach loop to iterate through all dates using the "yymmdd" format? Also, Can we possibly store the "yyMMdd" into an array since it will change each time during the foreach loop?
Upvotes: 0
Views: 2515
Reputation: 2739
List<string> result = new List<string>();
for (DateTime d = dateSTART.Value; d <= dateEND.Value; d = d.AddDays(1))
{
result.Add(d.ToString("yyMMdd"));
}
Upvotes: 0
Reputation: 67273
For starters, you need to get the dates in DateTime
format, not as strings.
for (DateTime d = dateSTART.Value; d <= dateEND.Value; d = d.AddDays(1))
{
// d contains the date for this iteration
}
Upvotes: 9