Results 1 to 6 of 6
  1. #1
    Alkady81 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2015
    Posts
    3

    Post Convert Listed Dates to Duration to Calculate Equipment Rental Fees

    Hi all

    I'm new in access
    I working on DB for my company equipment

    I used tables and queries and reached to the following query

    Query name (02-By Project)


    KSC_NO From_Project To_project Date_of_Trans
    K-01-037 52500 12013 02/14/2014
    K-01-037 12013 52500 03/31/2015
    K-01-037 52500 12013 04/07/2015


    K-01-129 52500 12013 03/03/2015



    I want to make query to give me the following

    KSC_NO IN_Date Out_date Duration (months)
    K-01-037 02/14/2014 03/31/2015 13.6667
    K-01-037 04/07/2015 Today 0.0333
    K-01-037 03/03/2015 Today 1.2


    Is that possible?


    Thanks and Regards

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    There is no query that can do that.
    it would require programming to run the data sequentially to determine each record's time span.

  3. #3
    Alkady81 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2015
    Posts
    3
    Quote Originally Posted by ranman256 View Post
    There is no query that can do that.
    it would require programming to run the data sequentially to determine each record's time span.
    can you tell me which programming?

  4. #4
    Rawb is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    Theoretically it can be done, but we would need to know the exact design of your Table. And, depending on the design, there might need to be pretty strict restrictions on how and when users can enter data.

    For example, assuming you have the following design:
    Projects Table

    • ID - Autonumber, Long Integer, Primary Key.
    • KSC_No - Text, 8 characters.
    • From_Project - Number, Integer.
    • To_Project - Number, Integer.
    • Date_Of_Trans - Date/Time. Short Date.
    • Is_Start_Date - Yes/No.

    As long as all matching date pairs follow the rules below, you can do it:
    1. Both Records must have the same KSC_No.
    2. The From_Project of the first Record must match the To_Project of the other Record
    3. The To_Project of the first Record must match the From_Project of the other Record
    4. The second Record (the end date) must be entered BEFORE a new start date is entered unless the new start date has a different KSC_No, From_Project, or To_Project.
    5. The first record (the start date) must have Is_Start_Date checked.
    6. The second record (the end date) must NOT have Is_Start_Date checked.

    As long as all of those rules are obeyed, the following Query can be used:
    Code:
    SELECT 
        A.ID, 
        A.KSC_No, 
        A.From_Project, 
        A.To_Project, 
        A.Date_Of_Trans AS Date_Start, 
        Nz((
            SELECT
                Min(C.Date_Of_Trans)
            FROM
                Projects AS C
            WHERE
                C.ID > A.ID AND
                C.KSC_No = A.KSC_No AND
                C.From_Project = A.To_Project AND
                C.Is_Start_Date=False
            GROUP BY
                C.Date_Of_Trans
            ORDER BY
                C.Date_Of_Trans
        ),Date()) AS Date_End
    FROM 
        Projects AS A
    WHERE 
        A.Is_Start_Date=True
    I've included a DB with an example.
    Attached Files Attached Files
    Last edited by Rawb; 04-08-2015 at 08:38 AM. Reason: Added some formatting

  5. #5
    Rawb is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    I just realized that, with the Query I provided earlier, it's theoretically possible (although unlikely) to link a start date to the wrong end date.

    To correct the issue, I've changed the main Query a bit. I also created a second Query that references the first and includes all the data.

    Attached is an updated database. This one also includes a simple Report that shows how you can use the Query results to determine duration and whether or not there's a hard end date.
    Attached Files Attached Files

  6. #6
    Alkady81 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2015
    Posts
    3
    Quote Originally Posted by Rawb View Post
    I just realized that, with the Query I provided earlier, it's theoretically possible (although unlikely) to link a start date to the wrong end date.

    To correct the issue, I've changed the main Query a bit. I also created a second Query that references the first and includes all the data.

    Attached is an updated database. This one also includes a simple Report that shows how you can use the Query results to determine duration and whether or not there's a hard end date.
    thanks Rawb, that's worked for me

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

Similar Threads

  1. Replies: 5
    Last Post: 06-22-2014, 12:10 AM
  2. Calculate duration between two dates
    By Tommy1005 in forum Queries
    Replies: 3
    Last Post: 07-02-2012, 05:41 AM
  3. Replies: 1
    Last Post: 11-12-2010, 01:16 AM
  4. How to calculate duration in hours & minutes
    By joypanattil in forum Access
    Replies: 0
    Last Post: 11-25-2009, 04:49 AM
  5. Replies: 5
    Last Post: 09-16-2009, 05:22 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