Results 1 to 7 of 7
  1. #1
    st1300 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    24

    Datediff()

    Hey folks,

    I would like to use the Datediff() function to do the below (which works) but I would like to add a twist but have yet to solve.

    IIf(DateDiff("m",[tblService2].[CompletionDate],Now())>3,"Yes","NO")



    What I'm hoping to do is do the above but have it "do something" a week before the 3 months are reached. So, I thought of the ww interval but that could get messy as I would like to keep the month interval.

    I've not yet started testing with the ww to see how it actually works but I assume it counts the # off weeks between date1 and date2.

  2. #2
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    if completion date = Date()-7

  3. #3
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    First off, DateDiff using months will return a 1 even if you were comparing between November 30th and December 1st. So, the question is do you care? But if you do, then you might want to use days instead (because weeks will also give you a 1 if used between the last day of the month and the first day of the next month if they are on a different week).

    IIf(DateDiff("d",[tblService2].[CompletionDate], Now()) > 83 And < 90, "Do Something", IIf(DateDiff("d",[tblService2].[CompletionDate], Now()) >=90, "Yes", "NO"))

  4. #4
    st1300 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    24
    Quote Originally Posted by boblarson View Post
    First off, DateDiff using months will return a 1 even if you were comparing between November 30th and December 1st. So, the question is do you care? But if you do, then you might want to use days instead (because weeks will also give you a 1 if used between the last day of the month and the first day of the next month if they are on a different week).

    IIf(DateDiff("d",[tblService2].[CompletionDate], Now()) > 83 And < 90, "Do Something", IIf(DateDiff("d",[tblService2].[CompletionDate], Now()) >=90, "Yes", "NO"))

    Funny, I was just coming to the day realization be not on paper so to speak but in my mind. So, yes going to put the day idea in motion.

    Thanks.
    Last edited by st1300; 12-08-2011 at 05:18 PM. Reason: erorr

  5. #5
    st1300 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    24
    Quote Originally Posted by st1300 View Post
    Funny, I was just coming to the day realization be not on paper so to speak but in my mind. So, yes going to put the day idea in motion.

    Thanks.

    Hmm sytax error with comma, but what?

    IIf(DateDiff("d", [tblService2].[CompletionDate], Now()) > 83 And < 90, "Yes","NO")

    Only thing I'm wondering is the second argument if you will is not the yes no of the iif ?? If that is how one would say it.

  6. #6
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Oops, my bad. You would need to change it to:

    Code:
    IIf(DateDiff("d", [tblService2].[CompletionDate], Now()) > 83 And DateDiff("d", [tblService2].[CompletionDate], Now())< 90,"Yes","NO")

  7. #7
    st1300 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    24
    Quote Originally Posted by boblarson View Post
    Oops, my bad. You would need to change it to:

    Code:
    IIf(DateDiff("d", [tblService2].[CompletionDate], Now()) > 83 And DateDiff("d", [tblService2].[CompletionDate], Now())< 90,"Yes","NO")
    Hmm always evaluates to NO. I wonder if the AND is causing the iif to get confused?

    Ok, I think I see what is going on now. The evaluate state is between 83 and 90 and anything oustside of this will go to NO, which is exactly what we asked of it. Not were I want to go but close. Some tweaking needed.

    Yes, that is it (above line). Working as should.

    Thanks.
    Last edited by st1300; 12-08-2011 at 07:28 PM. Reason: addition

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