Search This Blog

Thursday, October 4, 2012

Code for day in one year

Query: Code for date between two year's.



        public void date()
        {
            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 dtTemp = default(DateTime);
            while (dtStart <= dtEnd)
            {
                dtTemp = dtStart.AddDays(1);
                if (dtTemp < dtEnd)
                    s = s + dtStart.ToString("dd MMMM yyyy") +"\r\n\n";
                else
                {
                    s = s + dtStart.ToString("dd MMMM yyyy") + "\r\n\n";
                    break;
                }
             
                dtStart = dtTemp;
            }
         
            Response.Write(HttpUtility.HtmlEncode(s).Replace("\n", "<br />"));
         
        }

 OUT PUT:

01 April 2011

02 April 2011

03 April 2011

04 April 2011

05 April 2011

06 April 2011

07 April 2011

08 April 2011

09 April 2011

10 April 2011

11 April 2011

12 April 2011

13 April 2011

14 April 2011

15 April 2011

16 April 2011 

No comments :