Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    pranvera is offline Novice
    Windows 7 Access 2007
    Join Date
    Oct 2010
    Posts
    8

    how to filter weekends

    Hello guys,

    I am new user with access 2007 and I happy if you would help me with one problem I am not able to sort out.

    I need make query to filter daily delivered loads which are not older than 3 days. For this I am trying to filter in table delivered loads by funcion <date()-3 . However, I have problem with weekends because I need to skip them.

    For example: on Monday I need to start count loads from last friday (monday I will see loads from sunday, saturday,friday,thursday,wednesday.), On Tuesday I need to see loads for monday, sunday,saturday,friday and thursday. On Friday I need to see loads from Thursday,Wednesday and Thuesday.

    I tried something like :


    WHERE (((IIf(Weekday(Date())=3,(Date()-[Req Delivery Dt/Tm])<=5,(Date()-[Req Delivery Dt/Tm])<=3))<>False));

    Thank you for any idea.

  2. #2
    NTC is offline VIP
    Windows Vista Access 2007
    Join Date
    Nov 2009
    Posts
    2,392
    I don't believe the issue is weekends per se - because they always occur in the same place relative to your starting day. I think the issue is determing the correct formula.

    for each potential day determine the correct formula to identify all appropriate ship days via DateAdd method

    then string those formulas together with an IIF i.e. if start date is Monday then use Monday formula, if start date is Tuesday use Tuesday formula... ( obviously you could use If/Then or Case method if in vb)

    from your post it wasn't clear that as to whether or not each day had a differing formula or not - it seemed like they might, it was difficult to understand your post. Probably so because the weekend days are mathmatically different if one starts from a Monday vs a Wed......But in any case it doesn't matter. The concept is the same.

    Hope this helps a little.

  3. #3
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    if you don't count holidays, you can use following formula to skip Saturday and Sunday:

    >= iif(datepart("w",date) <=4 ,date-5,date-3)
    Last edited by weekend00; 10-14-2010 at 12:33 PM.

  4. #4
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by pranvera View Post
    Hello guys,

    I am new user with access 2007 and I happy if you would help me with one problem I am not able to sort out.

    I need make query to filter daily delivered loads which are not older than 3 days. For this I am trying to filter in table delivered loads by funcion <date()-3 . However, I have problem with weekends because I need to skip them.

    For example: on Monday I need to start count loads from last friday (monday I will see loads from sunday, saturday,friday,thursday,wednesday.), On Tuesday I need to see loads for monday, sunday,saturday,friday and thursday. On Friday I need to see loads from Thursday,Wednesday and Thuesday.

    I tried something like :
    WHERE (((IIf(Weekday(Date())=3,(Date()-[Req Delivery Dt/Tm])<=5,(Date()-[Req Delivery Dt/Tm])<=3))<>False));

    Thank you for any idea.
    pranvera,

    it may just be as simple as this as well:
    Code:
    WHERE [datefield] > dateadd("d", -4, date()) AND
    
    weekday([datefield]) BETWEEN 1 and 5

  5. #5
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    I'll go one even easier:
    WHERE [datefield] <= dateAdd("w", -3, Date())

  6. #6
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by slave138 View Post
    I'll go one even easier:
    he wants newer than 3 days, not older.

  7. #7
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    Read his description again. He wants the deliveries from the last 3 weekdays.

    EDIT: My apologies - you were right. It should be:
    WHERE [datefield] >= dateAdd("w", -3, Date())
    Last edited by slave138; 10-14-2010 at 01:56 PM. Reason: Correction

  8. #8
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    he wants 5 days if now is Monday, Tuesday, or Wednesday.

    For example: on Monday I need to start count loads from last friday (monday I will see loads from sunday, saturday,friday,thursday,wednesday.), On Tuesday I need to see loads for monday, sunday,saturday,friday and thursday. On Friday I need to see loads from Thursday,Wednesday and Thuesday.

  9. #9
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    Quote Originally Posted by weekend00 View Post
    he wants 5 days if now is Monday, Tuesday, or Wednesday.
    That means he wants to see everything going back 3 week days. If there is a weekend in the middle, it will come out to 5 days but all that really matters is that it goes back 3 week days.

  10. #10
    pranvera is offline Novice
    Windows 7 Access 2007
    Join Date
    Oct 2010
    Posts
    8
    Quote Originally Posted by slave138 View Post
    WHERE [datefield] <= dateAdd("w", -3, Date())

    thank you guys for all answers.

    When I try use formula: WHERE [datefield] <= dateAdd("w", -3, Date()) query has problem with syntax and always trys to marked coma between w and -3.

    I wanna apologize for my poor english and desribtion of my problem.
    Yes, I need to query shows always 3 last days, If there is a weekend in the middle need to see 5 last days.

  11. #11
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    If you wouldn't mind uploading a sample it would help figure out what is missing. All it would need to include is a blank copy of the tables and the query.

  12. #12
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    dateAdd("w", -3, Date()) is same as dateAdd("y",-3,date()) or dateAdd("d", -3, Date()) , it doesn't skip weekend.

    we still need IIF

  13. #13
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    Quote Originally Posted by weekend00 View Post
    dateAdd("w", -3, Date()) is same as dateAdd("y",-3,date()) or dateAdd("d", -3, Date()) , it doesn't skip weekend.

    we still need IIF
    My apologies. I was confused by what they meant by "weekday" thinking they were using the term the same way they use it in Outlook instead of referring to the day number within the week.

    I would agree that your example would probably be the shortest way to do it.

    Code:
    >= iif(datepart("w",date) <=4 ,date-5,date-3)

  14. #14
    pranvera is offline Novice
    Windows 7 Access 2007
    Join Date
    Oct 2010
    Posts
    8
    Quote Originally Posted by slave138 View Post

    I would agree that your example would probably be the shortest way to do it.

    Code:
    >= iif(datepart("w",date) <=4 ,date-5,date-3)
    I see. Trying to use this formula query asks for date parameters. Am I doing anything wrong if my SQL looks like :

    SELECT MarDaily.*
    FROM MarDaily
    WHERE (((MarDaily.[Req Delivery Dt/Tm])>= iif(datepart("w",date) <=4 ,date-5,date-3)));

  15. #15
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    Try:
    Code:
    SELECT MarDaily.*
    FROM MarDaily
    WHERE (((MarDaily.[Req Delivery Dt/Tm])>= iif(datepart("w",date()) <=4 ,date()-5,date()-3)));

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. How do I filter on this ?
    By _Chris_ in forum Access
    Replies: 7
    Last Post: 08-12-2010, 08:34 PM
  2. Another removing weekends question
    By catguy in forum Access
    Replies: 6
    Last Post: 08-03-2010, 07:59 AM
  3. Filter on #Num!
    By marley in forum Access
    Replies: 5
    Last Post: 07-28-2010, 06:59 AM
  4. Weekday excluding weekends
    By jd316632 in forum Queries
    Replies: 3
    Last Post: 05-24-2010, 02:01 PM
  5. Query DateDiff calculation excluding weekends
    By Masterfinn in forum Queries
    Replies: 3
    Last Post: 04-01-2010, 09:46 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