Skip to main content

Finding difference between two dates in months or years

Is it possible to calculate the 2 different dates in months or years? ? 

Brian Element Mon, 02/20/2017 - 07:57

Hi Bibin,

That is an intersting question.  There are probably several ways to solve this.  I did it in the equation editor with the following equation:

(@year(DATE1) + (@Month(DATE1) / 12)) - (@year(DATE2)+ (@Month(DATE2)/ 12))

The problem with this is it does not take into account a scenario where one date is March 31 and the second date is April 1, it would show as 1 month when in fact it is only 1 day.

To get the number of months just take the remainder and multiply by 12.

Hope this helps.

Brian

CB Wed, 03/29/2017 - 04:07

Hi,
why not using the IDEA-Function (out of the box)?
 
Example:
-----------
 


Sub Main
'Mask: YYYYMMDD

d1 = "20170301"
d2 = "20170329"

diff = iAge(d2, d1)
Msgbox diff,0,"Days Between"

End Sub

 
 
Result is 28.
 
cheers,
Chris
 
 
 
 

The website encountered an unexpected error. Try again later.