calculate every sunday in the year

How would you calculate every sunday in a given year?  I want to display in a repeater the date of every sunday in a given year just by knowing the current date.

Thanks in advance for any help.

-Dman100-Software ConsultantAsked:
Who is Participating?
rajeeshmcaConnect With a Mentor Commented:
Hi Dman100,

Try the following
Aspx page

            <asp:Repeater ID="SundayRepeater" runat="server">
                                Dates of Sunday in Current Year
                            <asp:Label ID="DateLabel" runat="server" Text='<%# Bind("SunDate") %>'>

Code Behind (cs Page)

protected void Page_Load(object sender, EventArgs e)
        DateTime dtCurrentDate;
        dtCurrentDate = DateTime.Now;
        DateTime dtStartDate = Convert.ToDateTime("01/01/" + dtCurrentDate.Year.ToString());
        DateTime dtEndDate =  Convert.ToDateTime("01/01/" + Convert.ToString(dtCurrentDate.Year + 1)).AddDays(-1);
        DataTable objDataTable = new DataTable();
        DataRow objDataRow;
        for (DateTime i = dtStartDate; i <= dtEndDate; i = i.AddDays(1))
            if (i.DayOfWeek == DayOfWeek.Sunday)
                objDataRow = objDataTable.NewRow();
                objDataRow["SunDate"] = i.ToShortDateString();
                i = i.AddDays(6);
        SundayRepeater.DataSource = objDataTable;
-Dman100-Software ConsultantAuthor Commented:
That is exactly what I needed.  I sincerely appreciate the help.  Thank you!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.