How to get the week number of the current month in C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • LoanB
    New Member
    • Nov 2007
    • 62

    How to get the week number of the current month in C#

    Hey gang

    Need some help please. Below I have code which returns the week number of the year.

    I need some code which simalarly return the week number of the current month.

    dtDate below gets passed a date picked from a datepicker.

    public static int GetWeekNumber(D ateTime dtDate)
    {
    CultureInfo ciCurr = CultureInfo.Cur rentCulture;
    int weekNum = ciCurr.Calendar .GetWeekOfYear( dt, CalendarWeekRul e.FirstFourDayW eek, DayOfWeek.Monda y);

    return weekNum;

    }

    Thanks,

    Lóan.
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Why not just take the "day" value, which would be 7 today.
    If you just need the number of "seven days" you are into a week, you could divide by 7.
    If you need the ACTUAL "weeks" (like since march of this year started on a saturday, then march2nd was "week two") you might need a day of week for the 1st of the month to determine it?
    Surely you could compute the week in the month from that?

    Comment

    Working...