• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 641
  • Last Modified:

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.

1 Solution
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-Author Commented:
That is exactly what I needed.  I sincerely appreciate the help.  Thank you!

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now