Thursday, August 23, 2018

Calculate Number of week between two days

Calculate  Number of  week  between two days

 void LeaveFunction()
    {


        int a, b, c;


        a = int.Parse(Label9.Text);

        // DateTime dateofleave = Convert.ToDateTime(TextBox1.Text, System.Globalization.CultureInfo.GetCultureInfo("hi-IN").DateTimeFormat);

        DateTime dateofjoining = Convert.ToDateTime(Label8.Text, System.Globalization.CultureInfo.GetCultureInfo("hi-IN").DateTimeFormat);
        //int i = dt1.Day - dt.Day;

        int numberOfWeeksOfService = NumberOfWeeks(dateofjoining, DateTime.Now);
        //  int numberOfWeeksBeforeLeave = NumberOfWeeks(DateTime.Now, dateofleave);
     
        Label10.Text = numberOfWeeksOfService.ToString();

        c = a + numberOfWeeksOfService;
        Response.Write(c.ToString());

        if (c == 1)
        {


        }
        else if (c == 2)
        {


        }
        else if (c == 3)
        {


        }
        else if (c == 4)
        {


        }
        else if (c == 5)
        {
            Response.Redirect("week5.aspx");

        }
        else
        {

            ScriptManager.RegisterStartupScript(this, this.GetType(), "alertmessage", "javascript:alert('week completed')", true);


        }





     

    }
    int NumberOfWeeks(DateTime dateFrom, DateTime dateTo)
    {
        TimeSpan Span = dateTo.Subtract(dateFrom);

        if (Span.Days <= 7)
        {
            if (dateFrom.DayOfWeek > dateTo.DayOfWeek)
            {
                return 2;
            }

            return 1;
        }

        int Days = Span.Days - 7 + (int)dateFrom.DayOfWeek;
        int WeekCount = 1;
        int DayCount = 0;

        for (WeekCount = 1; DayCount < Days; WeekCount++)
        {
            DayCount += 7;
        }

        return WeekCount;
    }

No comments:

Post a Comment

GRIDVIEW ON ROW DATA BOUND EVENT

 Database Create  Student : roll , name , city , cost  Fix 6 Value  in Database Record  ====================================================...