Search This Blog

Thursday, October 4, 2012

Code for how many week in financial year

Query:  Find out week in between two year's.

 public void weekly()
        {
            int startdate = 2011;
            int endDate = 2012;
            string s = string.Empty;
            DateTime dtStart = new DateTime(startdate, 4, 1);
            DateTime dtEnd = new DateTime(endDate, 3, 31);
            DateTime dtTemp2 = default(DateTime);
            DateTime dtTemp = default(DateTime);
            while (dtStart <= dtEnd)
            {
                dtTemp = dtStart.AddDays(6);
                if (dtTemp < dtEnd)
                    s = s + dtStart.ToString("dd MMMM yyyy") + " - " + dtTemp.ToString("dd MMMM yyyy") + "\r\n\n";
                else
                {
                    s = s + dtStart.ToString("dd MMMM yyyy") + " - " + dtEnd.ToString("dd MMMM yyyy") + "\r\n\n";
                    break;
                }
                dtTemp2 = dtTemp.AddDays(1);
                dtStart = dtTemp2;
            }
         
            Response.Write(HttpUtility.HtmlEncode(s).Replace("\n", "<br />"));
         
        }

Out Put:


01 April 2011 - 07 April 2011
08 April 2011 - 14 April 2011
15 April 2011 - 21 April 2011
22 April 2011 - 28 April 2011
29 April 2011 - 05 May 2011
06 May 2011 - 12 May 2011
13 May 2011 - 19 May 2011
20 May 2011 - 26 May 2011
27 May 2011 - 02 June 2011
03 June 2011 - 09 June 2011
10 June 2011 - 16 June 2011
17 June 2011 - 23 June 2011
24 June 2011 - 30 June 2011
01 July 2011 - 07 July 2011
08 July 2011 - 14 July 2011
15 July 2011 - 21 July 2011 



No comments :