Calculating the difference between dates

  • Thread starter Thread starter Jonathan
  • Start date Start date
J

Jonathan

I have a form in which I need to calculate the difference
between 2 dates and have the result displayed in another
field. The result should be displayed in years and with
fractions. Is this possible? Please assist! Thanks
 
Yes, it is possible. I just want to make sure that you mean "in another
control", not "in another field".

To create a calculated control, set the Control Source of the control (i.e.
textbox) to an equation. What do you want the "fraction" to look like,
x/365?

Example:
=IIf(CDate(Format(txtDate1, "mm/dd") & "/" & Year(txtDate2)) >=
CDate(txtDate2), DateDiff("yyyy", txtDate1, txtDate2) - 1 & " Years and " &
DateDiff("d", dateadd("yyyy", datediff("yyyy", txtDate1,
txtDate2),txtDate1), txtDate2) & " Days",DateDiff("yyyy", txtDate1,
txtDate2) & " Years and " & DateDiff("d", dateadd("yyyy", datediff("yyyy",
txtDate1, txtDate2),txtDate1), txtDate2) & " Days")
 
Back
Top