Get Dates of all Sundays in specific month and year using C#

on Jan 03, 2013 10:04 PM


Can any one give me a code for getting the date of sundays in the selected months and year and store it in the list of int.

Hope this is clear.

Please let me know if this is not clear.



Download FREE API for Word, Excel and PDF in ASP.Net: Download
on Jan 03, 2013 10:48 PM

Here's the script and the same can be used for different months, years or days

List<DateTime> dates = new List<DateTime>();
int year = 2013;
int month = 1;
DayOfWeek day = DayOfWeek.Sunday; 
System.Globalization.CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
for (int i = 1; i <= currentCulture.Calendar.GetDaysInMonth(year, month); i++)
    DateTime d = new DateTime(year, month, i);
    if (d.DayOfWeek == day)