Results 1 to 5 of 5
  1. #1
    coldstart is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    3

    Date of last Wednesday of any given month in any given year

    Federal reporting requires me to be able to calculate the actual date value of the last Wednesday of JAN, APR, JUL and OCT in any given year. I need the date value to allow me to select reporting data using that specific date. For example: I need to select all records that were in a table on or before the last Wednesday of January in the current year. So, I need a way to compute that the last Wednesday of January was, in fact, 01/25/2012.



    The solution may be simple, but it is eluding me. Can anyone steer me in the right direction? I would be MOST grateful.

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I'll show you how to do this in a two-step process, though you can combine both formulas into one, if you like.

    Let's say that you have some date field named "MyDate".
    First, let's get the last day of THAT month like this:
    Code:
    LastDay: DateSerial(Year([MyDate]),Month([MyDate])+1,0)
    Now, based on that calculation, let's get the last Wednesday of the month using the result of the calculated field above like this:
    Code:
    LastWednesday: IIf(Weekday([LastDay])>=4,[LastDay]-(Weekday([LastDay])-4),[LastDay]-(Weekday([LastDay])+3))

  3. #3
    coldstart is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    3
    That works, Joe! I'm still having trouble following the logic of it, but it works and I've lived long enough to learn one doesn't look a gift horse in the mouth.
    Thank you very much for enlightening me.

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Here are some "hints" that may help you out:

    LastDay calculation: If you build a date and use "0" for the day part, it will return the last day of the previous month. So building October 0, 2012 will actually return September 30, 2012.

    LastWednesday calculation: The WEEKDAY function pulls the weekday that a date falls on. Wednesday is represented by a "4". So, we just want to find the difference between the day the last day of the month falls on and Wednesday. If the last day is a Friday, that Weekday function would return a "6". If we subtract 4 from 6, we get two. So if we subtract 2 from our end of month calculation, we arrive at that Wednesday!

    If WEEKDAY returns a number less than 4, then we need to look back at the previous week, so we need to add 7 days (so instead of having a +4, we have a -3 (4-7=3).

    Let me know if you still need any more clarification on the logic.

  5. #5
    coldstart is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    3
    Thanks again, Joe. That does help.

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

Similar Threads

  1. month year date
    By slimjen in forum Database Design
    Replies: 6
    Last Post: 04-17-2012, 01:02 PM
  2. Separating a date into day, month and year
    By teirrah1995 in forum Reports
    Replies: 3
    Last Post: 07-17-2011, 02:17 PM
  3. Current Month and Year-To-Date
    By DSnipeFunk in forum Access
    Replies: 4
    Last Post: 05-31-2011, 11:38 AM
  4. Replies: 2
    Last Post: 03-26-2011, 02:43 PM
  5. by year by month
    By nkuebelbeck in forum Reports
    Replies: 21
    Last Post: 03-24-2010, 01:53 PM

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