View Full Version : Date Calculation showing years and months


karatelung
05-11-2001, 07:25 AM
I currently use this as my Control Source for an unbound text box to show the no. of years a client has been licensed:

=DateDiff("yyyy",[LicenseDate],Now())+Int(Format(Now(),"mmdd")<Format([licensedate],"mmdd"))

When a client has been licensed for less than 1 year, it shows "0". How can I get my text box to show years and months?

Thanks

GaryC
05-15-2001, 12:06 AM
Try

= DateDiff("yyyy", [LicenceDate], Now()) & " Yrs - " & DateDiff("m", [LicenceDate], Now()) - 12 * (DateDiff("yyyy", [LicenceDate], Now())) & " Mths"

karatelung
05-16-2001, 06:48 AM
Thanks, GaryC, you got me thinking in the right direction, but I had to make some adjustments.

Here is my final code for displaying a difference in the current date and an entered date that displays years and months in the same unbound text box:

=DateDiff("yyyy",[LicenseDate],Now()) & " years and " & DateDiff("m",[LicenseDate],Now())-(DateDiff("yyyy",[LicenseDate],Now())+Int(Format(Now(),"mmdd")<Format([licensedate],"mmdd")))*12 & " months"

Hope someone else can use this. If you're new to this, [LicenseDate] is the only thing that you'll have to change to get this to work for you.

Richie