Getting Start Date of Week

First, given a week number of the year, from (1-53), how do I can I calculate the first date in that week?

Here is how I get the week from a given day:

string[] date = new string[3];
date[0] = (this.cmbMonthE.SelectedIndex+1).ToString();
date[1] = this.cmbDayE.Items[this.cmbDayE.SelectedIndex].ToString();
date[2] = this.cmbYearE.Items[this.cmbYearE.SelectedIndex].ToString();

GregorianCalendar gCalendar = new GregorianCalendar();

try
{
DateTime usrE = new DateTime(int.Parse(date[2])+2000,int.Parse(date[0]),int.Parse(date[1]));
this.cmbWeekE.SelectedIndex = gCalendar.GetWeekOfYear( usrE,CalendarWeekRule.FirstFourDayWeek,DayOfWeek.Monday )-1;
}
catch(Exception err)
{}
[752 byte] By [Automatik] at [2007-11-19 11:05:46]
# 1 Re: Getting Start Date of Week
Easiest way I can think of is :-

1) Create a DateTime corresponding to 1st Jan of the year you want.
2) Call AddDays(7 * (weekNo - 1));
Tom_Hirst at 2007-11-9 1:49:49 >
# 2 Re: Getting Start Date of Week
I have a beautiful but different suggestion. How about using Julian dates? Julian dates are a bit different approach and I prefer them while working on C++. Also, its a lot fun working with it. You could do anything with them as you like just as numbers and forget about the complexities of datetime variables. See if they can be helpful in your scenario. :thumb: One possible solution to the date related issues is converting it into double format and Julian dates make our life a lot easier with such issues. Visit this link for a brief description about Julian dates.

http://aa.usno.navy.mil/data/docs/JulianDate.html

See the Javascript code about changing the dates to Julian formats and then back ( i hope its there! )

Now how to find the day of the week?
1. Take a sample date (any valid date) for which the week day is known to you (take today's date for ex.) and find its value in Julian format.
2. Now find the remainder of this julian date (just the integral part obv.) when divided with 7.
3. This remainder gives you that if remainder is say x then weekday is some day (say W, that you know) . From this you can easily deduce what week day would it be if the remainder is something else. For ex - if remainder is x+1 then weekday would be the day after W.

Similarly you could deduce other methods to find out whatever else you need to do with the dates. Hope you find this helpful. Stick to julian dates and you life would be really peaceful (addition, subtraction of dates get a lot easier).
To get the start day of the week, you would need to do some manipulations with the data like - julian date for the start date of the year, number of days in the year, week number you are interested in.

If you go on to finalize on implementing this I could guide you through the algorithms..they are pretty easy.
exterminator at 2007-11-9 1:50:49 >