15,667,864 members
0.00/5 (No votes)
See more:
Hi Team,
Required functionality is to get the return week number of a given date.
Supposed `8th March 2010` is the given date then it should return "2" as 2nd week. I have implemented a below method which return week number of the year, whereas requirement is return week no of the current month.
Could any body help me out from this scenario.
C#
```public static int GetWeekNumber(DateTime dtPassed)
{
CultureInfo ciCurr = CultureInfo.CurrentCulture;
int weekNum = ciCurr.Calendar.GetWeekOfYear(dtPassed, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
return weekNum;
}```

Tarun Singh. :laugh:
Thanks in Advance.

[Corrected broken formatting]
Posted
Updated 8-Mar-10 3:41am
v2

Solution 1

1. Check the day of the week for the 1st of given dates month
2. Take just the "day" value of given date
3. Based on point 1 & 2 and the factor 7 (days in a week), you can get it.
Right?

Though simpler approach would be:
1. Check the WeekOfYear of 1st of given date's month = x
2. Check the WeekOfYear of the given date = y
3. Week Number of current month = y-x+1

Hope that solves it all!

v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 OriginalGriff 278 Patrice T 70 Richard MacCutchan 20 Mike Hankey 10 Justin Porteous 5
 OriginalGriff 677 Richard MacCutchan 115 Patrice T 70 CPallini 50 Andre Oosthuizen 40

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900