Results 1 to 4 of 4
  1. #1
    dseeburg is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2011
    Posts
    2

    datediff problem

    Ok so im making a query that will select all the job postings from my database posted in the last 4 weeks. I dont want to hard code the exact date in as it wouldnt be the same tomorrow. Ive tried different variations of datediff() using the Now() function but i cant seem to get it right...any ideas on what im doing wrong?

  2. #2
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    Welcome to the forum

    If you want to return records where some date field is between today and what the date was 4 weeks ago (or 28 days ago) then I thing either one of these should work

    WHERE yourdatefield between dateadd("ww",-4,date()) and date()

    or

    WHERE yourdatefield between dateadd("d",-28,date()) and date()



    Using the datediff() function is also possible

    WHERE datediff("d", yourdatefield, date())<=28
    or
    WHERE datediff("ww", yourdatefield, date())<=4

  3. #3
    dseeburg is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2011
    Posts
    2
    when you say "yourdatefield" what do you mean by that exactly, is there a way to say for instance every time the database is opened and this query is ran that it would return the job postings in a span of 4 weeks from the day the query was ran every time...each way i write it i keep coming back to...yea its right today but if i opened it in a month the date wouldnt be a span of 4 weeks prior but rather 8 weeks...im not sure if im saying this right

    edit* well i came up with datediff("ww",[DatePosted], Now()) <= 4 would this work?....

    edit2* nm i see thats exactly what you were saying at the bottom....thanks for your help! i really appreciate it!

  4. #4
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    It sounds like you got it worked out; good luck with your project.

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

Similar Threads

  1. DateDiff
    By mrkaye in forum Forms
    Replies: 18
    Last Post: 11-19-2010, 08:19 AM
  2. DateDiff
    By ROB in forum Access
    Replies: 2
    Last Post: 10-30-2010, 03:58 AM
  3. How to use DateDiff?
    By teirrah1995 in forum Queries
    Replies: 10
    Last Post: 10-19-2010, 12:07 PM
  4. Need Help with Datediff
    By gonzod in forum Access
    Replies: 5
    Last Post: 08-26-2010, 02:29 PM
  5. Datediff
    By greggue in forum Queries
    Replies: 2
    Last Post: 08-13-2010, 03: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