Results 1 to 7 of 7
  1. #1
    kwooten is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    255

    Week Number of Month not Year?

    Is there anything i can put in the criteria of a query or VBA code that will provide me the week number of the month instead of the week number of the year?

  2. #2
    kwooten is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    255
    I have datepart('ww',[DateFilled]) gives me the week of the year; not month.

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Sorry, I deleted that. I have a cheat sheet that said:

    DatePart("w", dte)

    would return the week of the month ("ww" for week of the year), but I tested and it doesn't appear to work. I'll poke around, but have to head to another office to deal with a PC issue.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    You can try this

    Code:
    Function WeekOfMonth(Mydate As Date) As Integer
    'weeknumber of year based on your supplied Date - weeknumber of year of first of the month of the supplied Date
    WeekOfMonth = DatePart("ww", Mydate) - DatePart("ww", DateSerial(Year(Mydate), Month(Mydate), 1)) + 1
    End Function

  5. #5
    kwooten is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    255
    Quote Originally Posted by orange View Post
    You can try this

    Code:
    Function WeekOfMonth(Mydate As Date) As Integer
    'weeknumber of year based on your supplied Date - weeknumber of year of first of the month of the supplied Date
    WeekOfMonth = DatePart("ww", Mydate) - DatePart("ww", DateSerial(Year(Mydate), Month(Mydate), 1)) + 1
    End Function
    Forgive my ignorance, but where do i put this?

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Create a Module;
    Copy and paste this Function into the module; then save the module -- name it MyModule.
    Then the function becomes available to you wherever you want to use it (Query, vba etc)

    Then in a query, using your DateFilled, on your fields line use

    WeekInvolved: WeekOfMonth(DateFilled)

    When you run the query, you should see the week of the Month related to DateFilled

    More info on modules and vba at
    http://www.accessmvp.com/strive4peac...Chapter_02.pdf

  7. #7
    kwooten is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    255
    oh ok.. gotcha.. i didnt realize modules worked like that.. it gave me what i wanted so thanks for the help.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 10
    Last Post: 10-19-2012, 05:10 AM
  2. First week or business day of the month
    By Dutch1956 in forum Programming
    Replies: 12
    Last Post: 09-18-2011, 08:39 AM
  3. How to display week of the year
    By wongray in forum Access
    Replies: 2
    Last Post: 12-28-2010, 04:46 AM
  4. by year by month
    By nkuebelbeck in forum Reports
    Replies: 21
    Last Post: 03-24-2010, 01:53 PM
  5. Retrieving Week of Year in a date range
    By Korvega in forum Queries
    Replies: 2
    Last Post: 05-27-2006, 06:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums