Pages

Friday, January 1, 2010

Find week number from Date in asp.ne c#

Find the week from the date in asp.net c# :

Introduction : This article describe you how to find week number from date in c# .I have created one function which return you week number from the date in c#  .

C# Code for finding the week number :

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

namespace HamidSite
{
    public partial class Test : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {            
            int WeekNo = GetWeeknumber(DateTime.Now);
        }
        public int GetWeeknumber(DateTime Date)
        {
            try
            {   int iMonth = Date.Month;
                int returnNumber = 0;
                for (int i = 1; i <= 5; i++)
                {
                    if (iMonth == Date.AddDays(-7 * i).Month)
                    { }
                    else
                    {
                        returnNumber = i; break;
                    }
                }
                return returnNumber;  
            }
            catch (Exception Exc) { throw Exc; }
        }
    }
}

Related Other posts

9 comments: