Click to See Complete Forum and Search --> : Get all saturdays in a Year using c#


ajithev
August 19th, 2009, 05:11 AM
plz help me to find all saturdays in a year.

dannystommen
August 19th, 2009, 05:33 AM
DateTime start = new DateTime(2009, 1, 1);
DateTime end = new DateTime(2009, 12, 31);
List<DateTime> saturdays = new List<DateTime>();
while (start < end) {
if (start.DayOfWeek == DayOfWeek.Saturday) {
saturdays.Add(new DateTime(start.Year, start.Month, start.Day));
start = start.AddDays(7);
}
else {
start = start.AddDays(1);
}
}

I don't know if there is any function that gets all Saturdays in a year, but this code also works