by Raju Maharjan
19. June 2011 22:27
It seems there is no Week property on a DateTime instance. So I started looking for a way to get the week number. As it turns out the CultureInfo class will get you where you want to go using the Calendar property.
The C# method uses the DateTime object to get the week number of a given date. The number returned is dependent on the culture of the target machine and which will be the week number for the provided date.
-
public static int GetWeekNumber(DateTime dtSelectedDate)
-
{
-
CultureInfo ciCurr = CultureInfo.CurrentCulture;
-
int weekNum = ciCurr.Calendar.GetWeekOfYear(dtSelectedDate, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
-
return weekNum;
-
}