Results 1 to 8 of 8
  1. #1
    Oxygen Potassium is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2016
    Posts
    40

    Find Next Tuesday

    I have a database that is used as a task tracker and creates due dates based on the frequency (daily, weekly, monthly, etc..). I'm having difficulties working out a formula for determining the date of the next Wednesday, whether it be this week (if today is Mon-Wed) or next week (if today is Thurs-Fri).

    Right now I built a Function to return a specific date:

    AddWorkdaysX(StartDate As Date, NumDays As Integer) As Date


    I'm thinking something like IIF(date()<=Wednesday, Return this week Wednesday's date, Return next week Wednesday's date)

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    use the weekday function to determine the day of the week

    weekday(date()) for today (Tuesday), returns 3

    so a formula something like this

    date()+iif(weekday(date())<4,4,11)-weekday(date())

  3. #3
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Date + (8 - Weekday(date, vbTuesday))
    However, if you run this on a Tuesday, you will get Tuesday's date. You might need to incorporate that with the DateDiff function to test for the number of days difference (it would be zero). That function would also enable you to get the number of days until Tuesday, which you didn't ask for. I thought you might be interested in using that somehow.
    Edit: post said Wednesday, title said Tuesday. I went with Tuesday.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Here is a function that should be helpful. You can use it to find the Next whatever from any Date.

    Code:
    Function GetNextYourDay(dteMydate As Date, MyDay As Integer) As Date
    'dteMydate is the Date from which you are making the determination
    'myDay refers to the integer value of the Day where 1=sunday,2 = monday,3 = tuesday....
     GetNextYourDay = [dteMydate] - WeekDay([dteMydate]) + MyDay + IIf(WeekDay([dteMydate]) >= MyDay, 7, 0)
    End Function
    So to get next Wednesday, in the immediate window

    ?getnextyourday(Date,4) '4 represents Wednesday and Date is today( 7 June 2016)
    08/06/2016 '<-----Canadian regional setting

  5. #5
    Oxygen Potassium is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2016
    Posts
    40
    Thanks Micron.

    My formula now looks like this:

    IIf(Date()<=Weekday(Date(),3),AddWorkdaysX(Weekday (Date(),2),1),AddWorkdaysX(Date()+(8-Weekday(Date(),2)),1))

    My problem now is the statement is always coming back as false

  6. #6
    Oxygen Potassium is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2016
    Posts
    40
    Thanks Orange I think that function solved my problem.

    This is my formula to find the next Tuesday, which seems to work:

    IIf(Weekday(Date())<Weekday(Date(),4),AddWorkdaysX (getnextyourday(Date(),2)-7,1),AddWorkdaysX(getnextyourday(Date(),2),1))

  7. #7
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    There is no logic to handle "workdays". The function takes a date (dteMydate any date from which you do the measurement as parameter, and an integer from 1 thru 7 to indicate which day you want. The integer represents day from 1=sunday,2 - monday, 3=tuesday...7=saturday.

    To get the Thursday following OrderDate, you would use

    getnextyourday(OrderDate,5) which means get the next Thursday (day 5) after OrderDate.

  8. #8
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    and an integer from 1 thru 7
    Don't forget 0 - system default.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. To find out the first 2 max
    By murali in forum Access
    Replies: 1
    Last Post: 04-22-2014, 03:59 PM
  2. Find
    By sergran in forum Programming
    Replies: 2
    Last Post: 10-08-2013, 01:02 AM
  3. Replies: 2
    Last Post: 02-07-2012, 05:39 PM
  4. Replies: 9
    Last Post: 12-11-2011, 07:16 PM
  5. Find a SUM
    By jcsports31 in forum Access
    Replies: 8
    Last Post: 09-14-2010, 10:07 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