Search This Blog

Thursday, October 4, 2012

Code for financial year month

Query: Find out month between two year's.


public void fymonth()
        {
            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.AddMonths(1);
                if (dtStart < dtEnd)
                    s = s+ dtStart.ToString("MMMM yyyy") + "\r\n\n";
                else
                {
                    s = s+ dtStart.ToString("MMMM yyyy") + "\r\n\n";
                    break;
                }

                dtStart = dtTemp;
            }

            Response.Write(HttpUtility.HtmlEncode(s).Replace("\n", "<br />"));

        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            fymonth();
        }

Out Put:


April 2011

May 2011

June 2011

July 2011

August 2011

September 2011

October 2011

November 2011

December 2011

January 2012

February 2012

March 2012 

No comments :