Round date difference to nearest single decimal

Posted on 2014-08-28
Last Modified: 2014-08-28
I have this formula:

Me.txtCurrentLifeOfAsset = Int(([txtDateInventoryPerformed] - [txtDateofPurchase]) / 365.25)

Which calculates the difference between two dates in whole years.  For example 6/1/2014 - 3/1/2009 is giving me 5.0 years.  But I want it to show the decimal.  In other words 5.2

What do I have to change in the formula to make this possible?
Question by:SteveL13
    LVL 9

    Accepted Solution

    Use the Round() function, like this:

    Me.txtCurrentLifeOfAsset = Round(([txtDateInventoryPerformed] - [txtDateofPurchase]) / 365.25, 1)

    Open in new window

    LVL 48

    Expert Comment

    by:Gustav Brock
    If you don't need a high precision, this will do:

    DecimalYears = CDbl(Format(DateDiff("d", datFrom, datTo) / 365, "0.0"))


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
    In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
    With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now