We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Close Icon
Unfortunately, activation email could not send to your email. Please try again.
Close Icon
Syncfusion Feedback

Get the week number in year

Thread ID:





44586 May 28,2006 11:51 AM UTC Jun 2,2006 10:43 AM UTC WinForms 3
Tags: FAQ
Asked On May 28, 2006 11:51 AM UTC

hi, I want to know if there is a function that returns the number of a week in a certain year. for example: The week (from 24 june 2006 Till 30 june 2006) is the week #26 of the year 2006

Joy K George [Syncfusion]
Replied On May 29, 2006 09:48 AM UTC

Hi Myra, Import the namespace System.Globalization and try the following code snippet. private void Button1_Click(object sender, EventArgs e){ CultureInfo myCI = new CultureInfo("en-US"); Calendar myCal = myCI.Calendar; // Gets the DTFI properties required by GetWeekOfYear. CalendarWeekRule myCWR = myCI.DateTimeFormat.CalendarWeekRule; DayOfWeek myFirstDOW = myCI.DateTimeFormat.FirstDayOfWeek; // Displays the number of the current week relative to the beginning of the year. Console.WriteLine("The CalendarWeekRule used for the en-US culture is {0}.", myCWR); Console.WriteLine("The FirstDayOfWeek used for the en-US culture is {0}.", myFirstDOW); Console.WriteLine("Therefore, the current week is Week {0} of the current year.", myCal.GetWeekOfYear(DateTime.Now, myCWR, myFirstDOW)); } Regards, Joy

Replied On June 1, 2006 01:40 PM UTC

thanks joy!great!maybe u can help me doing the opposite work: function that gives the start and end day of a week number: so if I choose the first week of the year 2006, it will give me: 31/12/2006 --> 06/01/2006 if the week begins on saturday regards, Myra

Joy K George [Syncfusion]
Replied On June 2, 2006 10:43 AM UTC

Hi Myra, If my understanding about your requirement is right you could achieve using the below code. int week = int.Parse(textBox1.Text); int year = int.Parse(textBox2.Text); DateTime dt = new DateTime(year, 1, 1); dt=dt.AddDays(week * 7); //it will add days to the starting date (eg 1/1/2006) MessageBox.Show(dt.ToString()); Regards, Joy


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon