I had a DateTimeRange class and I needed to get the first day of every month that was covered by the range.
Here is the code:
49 public IEnumerable<DateTime> MonthStarts
50 {
51 get
52 {
53 var current = new DateTime(Start.Year, Start.Month, 1);
54
55 while (current <= End)
56 {
57 yield return current;
58 current = current.AddMonths(1);
59 }
60 }
61 }
This can then be used in simple foreach statements.
No comments:
Post a Comment