Calculating the Week Number in a given month

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • xraive
    New Member
    • Jun 2009
    • 30

    Calculating the Week Number in a given month

    I would like to know if there is a function available to determine the week number in any given month.

    For example March 20th, 2010 would be Week #3
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    To the best of my knowledge, there is no Function that will return the Week of the Month for a given Date. I through together a Custom Function that you can test, but I've had no time to test it myself and I am not sure of its accuracy.
    Code:
    Public Function fCalcWeekOfMonth(dteDate As Date) As Byte
      fCalcWeekOfMonth = DatePart("ww", dteDate) - _
                        DatePart("ww", DateSerial(Year(dteDate), Month(dteDate), 1)) + 1
    End Function
    Code:
    MsgBox fCalcWeekOfMonth(#3/20/2010#)
    returns
    Code:
    3

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32656

      #3
      I don't believe there is a built-in function available anywhere. You could write your own, but you'd need to be more clear as to what exactly constituted the first week before you started.

      Comment

      • missinglinq
        Recognized Expert Specialist
        • Nov 2006
        • 3533

        #4
        The OP's example would indicate, to me, that he wanted it just as it would appear on a printed calendar.

        I gave the code a pretty good test run, including Februarys with both 28 and 29 days, and could find no problems with it.

        Linq ;0)>

        Comment

        • xraive
          New Member
          • Jun 2009
          • 30

          #5
          Thank you so much ADezii for your prompt response.

          Comment

          • ADezii
            Recognized Expert Expert
            • Apr 2006
            • 8834

            #6
            You are quite welcome.

            Comment

            Working...