Calculating the difference between dates

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
 
W

Wayne Morgan

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")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top