• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 185
  • Last Modified:

Round date difference to nearest single decimal

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?
0
SteveL13
Asked:
SteveL13
1 Solution
 
McOzCommented:
Use the Round() function, like this:

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

Open in new window

0
 
Gustav BrockCIOCommented:
If you don't need a high precision, this will do:

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

/gustav
0

Featured Post

Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now