Results 1 to 6 of 6
  1. #1
    BaaBaaBristol is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2021
    Posts
    11

    Calculation using two dates

    Hello!
    I wondered if anyone could help me with a slightly more complex date calculation. There are two groups of clients that affect a calculation showing the length of engagement with our project:



    ACTIVE CLIENTS: Difference between Start Date and today's date.
    CLOSED CLIENTS: Difference between Start Date and End Date

    Start Date and End Date are entered on the main data entry form, but active clients will only have the start date.

    I have found the following formula before, which I assume would work with active clients:

    =DateDiff ("d",Date (), [StartDate])

    My questions is how do I adapt this formula to cover both instances of active and closed clients, to see if there is a value in Date Closed - if this is null, due to not ending yet, then I need it to continue comparing to today's date.
    I hope that is clear - I can clarify further if not.



  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,913
    Use IIF() function to determine which calculation and NZ() function to use Date() for active clients
    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

  3. #3
    BaaBaaBristol is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2021
    Posts
    11
    Thanks for your quick reply. Would you be able to illustrate an example of IIF that gives the calculation expresses in the case of TRUE and FALSE?

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,784
    IIF(IsNull([End Date]),Date-[Start Date],[End Date]-[Start Date])

    Could depend on where you're doing this. Maybe your post really belongs in Queries forum? The forum choice often provides useful clues to the responders.
    Last edited by Micron; 10-13-2022 at 10:16 AM. Reason: code edit
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    BaaBaaBristol is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2021
    Posts
    11
    Thanks for the reply. I am not sure where to put this formula. I have added a field called 'JourneyLength' to the main table that is acting as a client record. This table also holds fields 'DateFrom' and 'DateTo' for start and end dates.

    On the input form, I am using a text box which I am linking to 'JourneyLength' as the Control Source. I have tried putting the formula in as code for an event, but the syntax is rejected. I am only using:

    IIF(IsNull([DateTo]),Date-[DateFrom],[DateTo]-[DateFrom])

    Am I missing another function to make this work, or have I got the syntax or placement wrong?

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,913
    Code:
    Me.JourneyLength = IIF(IsNull([DateTo]),Date-[DateFrom],[DateTo]-[DateFrom])
    



    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

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

Similar Threads

  1. Replies: 21
    Last Post: 06-23-2020, 11:45 AM
  2. Replies: 2
    Last Post: 09-19-2017, 11:31 AM
  3. Replies: 8
    Last Post: 12-02-2013, 03:46 PM
  4. Calculation Field in table vs Query calculation
    By Leonidsg in forum Database Design
    Replies: 18
    Last Post: 02-28-2013, 09:38 PM
  5. Replies: 1
    Last Post: 02-12-2013, 02:33 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