Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying age in months or years using DateDiff

Status
Not open for further replies.

SaneN85

Technical User
Sep 17, 2009
10
0
0
US
Ok, I'm not sure what happened to my first thread, but I am going to post again. I currently am using the Date diff formula to get the age of patients.

Code:
=DateDiff("yyyy",[DOB],Now())+Int(Format(Now(),"mmdd")<Format([DOB],"mmdd"))

This displays the age of the patient in years, so if the patient is 3 months old, it is displayed as 0. What I am trying to do, is get it to display 3 months old (or whatever the correct month of patient's age) if they're under 1 years old. If they are over 1 (the majority will be), to display as their age in years. Is this even possible? If so, any help is appreciated.
 
use an IIF statement

something like .. untested

=IIf(DateDiff("yyyy",[DOB],Now())+Int(Format(Now(),"mmdd")<Format([DOB],"mmdd"))<1,DateDiff("mm",[DOB],Now())+Int(Format(Now(),"mmdd")<Format([DOB],"mmdd")),DateDiff("yyyy",[DOB],Now())+Int(Format(Now(),"mmdd")<Format([DOB],"mmdd")))

HTH << MaZeWorX >> "I have not failed I have only found ten thousand ways that don't work
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top