Created
May 16, 2018 15:38
-
-
Save matabares/8d7eb562ed476b2d09c7b8c0745f7154 to your computer and use it in GitHub Desktop.
Iterate over dates in c#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Main() | |
{ | |
DateTime StartDate = Convert.ToDateTime("15-08-2017"); | |
DateTime EndDate = Convert.ToDateTime("15-08-2017"); | |
foreach (DateTime day in EachCalendarDay(StartDate, EndDate)) | |
{ | |
Console.WriteLine("Date is : " + day.ToString("dd-MM-yyyy")); | |
} | |
} | |
// Define other methods and classes here | |
public IEnumerable<DateTime> EachCalendarDay(DateTime startDate, DateTime endDate) | |
{ | |
for (var date = startDate.Date; date.Date <= endDate.Date; date = date.AddDays(1)) yield | |
return date; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment