Search This Blog

Monday, October 8, 2012

Find out week in month find week range

Query: How can find out week in month find week range.



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SBIWEB
{
    public partial class weekly : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        private string getDatetm(DateTime dt)
        {

            string s = string.Empty;
            DateTime dtTempS = dt;
            DateTime dtTempL = dt;
            int daysLeft = 7;
            int totalDayRemaing = DateTime.DaysInMonth(dt.Year, dt.Month);
            if ((int)dt.DayOfWeek != 1)
            {
                daysLeft = (int)dt.DayOfWeek;
                if (daysLeft == 0)
                    daysLeft = 8;
                daysLeft = 7 - daysLeft + 1;
            }
            while (totalDayRemaing > 7)
            {
                dtTempL = dtTempS.AddDays(daysLeft - 1);
                s = s + dtTempS.ToString("dd/MM") + " - " + dtTempL.ToString("dd/MM") + "\r\n";
                dtTempS = dtTempL.AddDays(1);
                totalDayRemaing = totalDayRemaing - (daysLeft);
                daysLeft = 7;
            }
            dtTempL = dtTempS.AddDays(totalDayRemaing - 1);
            s = s + dtTempS.ToString("dd/MM") + " - " + dtTempL.ToString("dd/MM") + "\r\n";
            return s;
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string s = string.Empty;
            DateTime dtStart = new DateTime(2012, 3, 1);
            DateTime dtEnd = new DateTime(2013, 4, 30);
            while (dtStart.Year < dtEnd.Year || dtStart.Month <= dtEnd.Month)
            {
                s = s + getDatetm(dtStart);
                dtStart = dtStart.AddMonths(1);
            }
            Response.Write(HttpUtility.HtmlEncode(s).Replace("\n", "<br />"));
        }
    }
}

Output:

01/03 - 04/03
05/03 - 11/03
12/03 - 18/03
19/03 - 25/03
26/03 - 31/03 

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 



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 

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