Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
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

1 solution

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!
 
Share this answer
 
v3

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



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