Results 1 to 6 of 6
  1. #1
    Harry W is offline Novice
    Windows 11 Office 365
    Join Date
    Mar 2024
    Posts
    3

    Query formula


    This Formula works.
    DC: DateDiff("yyyy",[DominionServiceDate],[Expiry-Date]+1)

    I have created a new query and want to change the formula to give an answer based on today's date, not the Expiry date.
    TY

  2. #2
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Try

    DC: DateDiff("yyyy",[DominionServiceDate],Date()+1)

  3. #3
    Harry W is offline Novice
    Windows 11 Office 365
    Join Date
    Mar 2024
    Posts
    3

    Thank You

    I have tried this several different times.

    Date() returns a number that is one too high. When I remove +1 it continues to return a number one too high. When I change it too -1 it continues to return the number at 1 too high. I tried +5 and it returned a number that is one number too high.


    Quote Originally Posted by davegri View Post
    Try

    DC: DateDiff("yyyy",[DominionServiceDate],Date()+1)

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by Harry W View Post
    I have tried this several different times.

    Date() returns a number that is one too high. When I remove +1 it continues to return a number one too high. When I change it too -1 it continues to return the number at 1 too high. I tried +5 and it returned a number that is one number too high.
    You are adding 1 day to the date or 5 if you use 5.

    You need to understand code that you are using?

    Just what would you expect to get from
    Code:
    tt=#03/14/2022#
    ? DateDiff("yyyy",tt,Date()+1)
     2
    Was your expiry date always the last date in the year?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    I have tried this several different times.
    Your code returns the number of years between two dates specified. Is that what you want?
    Perhaps give us some sample values of DominionServiceDate and what you want as result.

  6. #6
    Harry W is offline Novice
    Windows 11 Office 365
    Join Date
    Mar 2024
    Posts
    3

    Thank You

    TY very much.
    I got it now.
    I was adding one day not one year.

    I needed to come up with a new formula because many folks have expiry dates well beyond 2024.
    And to answer your question below Yes; the expiry day date is always 31 Dec and the Service Date is always 1 Jan

    Again TY

    Quote Originally Posted by Welshgasman View Post
    You are adding 1 day to the date or 5 if you use 5.

    You need to understand code that you are using?

    Just what would you expect to get from
    Code:
    tt=#03/14/2022#
    ? DateDiff("yyyy",tt,Date()+1)
     2
    Was your expiry date always the last date in the year?

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

Similar Threads

  1. Formula in a Query
    By spyldbrat in forum Access
    Replies: 6
    Last Post: 01-05-2018, 08:05 AM
  2. Replies: 19
    Last Post: 07-13-2015, 10:15 AM
  3. Replies: 41
    Last Post: 05-29-2015, 02:58 PM
  4. Formula in Query
    By LeadTechIG in forum Queries
    Replies: 6
    Last Post: 05-12-2015, 05:50 AM
  5. Need help with Query formula
    By krymer in forum Queries
    Replies: 5
    Last Post: 09-30-2010, 06:51 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