G
Guest
Hi
Im using GregorianCalendar to find out the current years week numbers.
When the user chooses a week number in a dropdown i want to show that week
in a table with the corresponding dates.
For example : the user choses week43 (this week)
so somehow i must calculate what date is startdate that week (monday 18th).
How do i do this with c# ?
all i know is that its-
year: 2004
and week: 43
Ive been thinking about doing it the ugly way .. by taking weeknumber*7 to
get the day of year ... but that wouldnt be accurate since not all weeks have
7 days.
Then I thought about making a loop that goes thru all the days of the year
checking what week that date is in and if its 43 then jump out and return the
date.
But that would be very ugly ... and take unnecessary resources imo.
the Gregorian code is as follows :
GregorianCalendar gCalendar = new GregorianCalendar();
int YearNumber = gCalendar.GetYear(DateTime.Now);
string strMaxDate = YearNumber.ToString() + "-12-31";
int MaxWeekNumber = gCalendar.GetWeekOfYear(Convert.ToDateTime(strMaxDatum),
CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
for(int r = 1; r < MaxWeekNumber+1; r++)
{
selectWeek.Items.Add("Week " + r.ToString());
}
Im using GregorianCalendar to find out the current years week numbers.
When the user chooses a week number in a dropdown i want to show that week
in a table with the corresponding dates.
For example : the user choses week43 (this week)
so somehow i must calculate what date is startdate that week (monday 18th).
How do i do this with c# ?
all i know is that its-
year: 2004
and week: 43
Ive been thinking about doing it the ugly way .. by taking weeknumber*7 to
get the day of year ... but that wouldnt be accurate since not all weeks have
7 days.
Then I thought about making a loop that goes thru all the days of the year
checking what week that date is in and if its 43 then jump out and return the
date.
But that would be very ugly ... and take unnecessary resources imo.
the Gregorian code is as follows :
GregorianCalendar gCalendar = new GregorianCalendar();
int YearNumber = gCalendar.GetYear(DateTime.Now);
string strMaxDate = YearNumber.ToString() + "-12-31";
int MaxWeekNumber = gCalendar.GetWeekOfYear(Convert.ToDateTime(strMaxDatum),
CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
for(int r = 1; r < MaxWeekNumber+1; r++)
{
selectWeek.Items.Add("Week " + r.ToString());
}