Results 1 to 4 of 4
  1. #1
    philbill is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    9

    Using DateDiff on a query to calculate roof life


    I have a table tblRepairs with fields for address, RepairDate and RepairType. Values for RepairType are entered via combo box: NewFlat, NewShingle, RepairFlat, RepairSingle. Repair dates go back to the mid 1990's so I have duplicate address to account for these values. For example: each of these addresses may have dates for each NewShinlge,RepairShingle, NewFlat, another NewShingle (indicatiing a new roof).

    I want to be able to calculate roof life between NewShingles and NewFlats for each address.

    Haven't a clue how to begin.

    I'm using Windows XP and Access 2002

    Help would be greatly appreciated.

    Thank you

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    In a query calc the life of the tile...
    Select DateAdd("yyyy",[LifeOfTiles],[InstallDate]) as ExpireDate from table

  3. #3
    philbill is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    9
    Thanks for your response ranman. I played around with your suggestion and experimented to come up with this query (SQL);

    SELECT Repair.UnitID, Max(Repair.RepairDate) AS MaxOfRepairDate, Last(Repair.RepairDate) AS LastOfRepairDate, Repair.RepairType, DateDiff("yyyy",[LastofRepairDate],[MaxofRepairDate]) AS RoofLife
    FROM Repair
    GROUP BY Repair.UnitID, Repair.RepairType, DateDiff("yyyy",[LastofRepairDate],[MaxofRepairDate])
    HAVING (((Repair.RepairType)="Flat Roof New"));

    I did the same for Shingle Roofs and have what I want for the most part. Agan thanks for your response.

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Just a word of warning. The "Last()" function returns the last record in the recordset, not the earliest date.
    I don't know your table structures or relationships, but really check that the dates are what you need/are correct. Most people that use the "First()" and "Last()" functions don't really understand what they return.


    Good luck with your project......

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

Similar Threads

  1. Replies: 3
    Last Post: 02-16-2016, 05:02 PM
  2. Calculate DateDiff on Time Added Field
    By athyeh in forum Queries
    Replies: 9
    Last Post: 12-18-2013, 02:10 PM
  3. Replies: 2
    Last Post: 10-03-2013, 01:01 PM
  4. Replies: 1
    Last Post: 05-01-2013, 10:53 AM
  5. Replies: 7
    Last Post: 07-25-2011, 02:50 AM

Tags for this Thread

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