locked
Finding Week of the Month RRS feed

  • Question

  • Hi,

    I want to find out week of the month.

    A month consist of weeks and i want to find out which week of the current month.

    Thanks.

    Regards
    Kashif

    Sunday, May 10, 2009 6:12 AM

Answers

  • Something like

    Dim

    a1 As DateTime = Today.ToString
    Dim ciCurr As CultureInfo = CultureInfo.CurrentCulture
    Dim weekNum As Double = (ciCurr.Calendar.GetDayOfMonth(a1)) / 7

    If
    weekNum <= 1 Then
            MsgBox("First Week")
    ElseIf weekNum > 1 And weekNum <= 2 Then
            MsgBox("Second Week")
    ElseIf weekNum > 2 And weekNum <= 3 Then
            MsgBox("Third Week")
    ElseIf weekNum > 3 And weekNum <= 4 Then
            MsgBox("Fourth Week")
    ElseIf weekNum > 4 Then
            MsgBox("Last Week")
    End If

    • Edited by Paramu Sunday, May 10, 2009 7:31 AM
    • Proposed as answer by Paramu Sunday, May 10, 2009 4:15 PM
    • Marked as answer by Martin Xie - MSFT Wednesday, May 13, 2009 12:07 PM
    Sunday, May 10, 2009 7:29 AM

All replies

  • You can divide by 7 and add 1.

    So 18 would give 18 / 7 = 2 + 1 = 3



    Thanks,
    A.m.a.L

    .Net Goodies
    [Remember to click "mark as answered" when you get a correct reply to your question]
    Sunday, May 10, 2009 6:27 AM
  • Something like

    Dim

    a1 As DateTime = Today.ToString
    Dim ciCurr As CultureInfo = CultureInfo.CurrentCulture
    Dim weekNum As Double = (ciCurr.Calendar.GetDayOfMonth(a1)) / 7

    If
    weekNum <= 1 Then
            MsgBox("First Week")
    ElseIf weekNum > 1 And weekNum <= 2 Then
            MsgBox("Second Week")
    ElseIf weekNum > 2 And weekNum <= 3 Then
            MsgBox("Third Week")
    ElseIf weekNum > 3 And weekNum <= 4 Then
            MsgBox("Fourth Week")
    ElseIf weekNum > 4 Then
            MsgBox("Last Week")
    End If

    • Edited by Paramu Sunday, May 10, 2009 7:31 AM
    • Proposed as answer by Paramu Sunday, May 10, 2009 4:15 PM
    • Marked as answer by Martin Xie - MSFT Wednesday, May 13, 2009 12:07 PM
    Sunday, May 10, 2009 7:29 AM