?
Solved

Calculated age field rounding up

Posted on 2006-05-18
4
Medium Priority
?
242 Views
Last Modified: 2010-04-07
I am calculating camper's age at camp date using DateDiff in a query.  However this formula rounds up giving me the wrong age for campers whose birthdays falls after camp.  Here's the formula I have in m y query:

        CampAge: DateDiff("yyyy",[DOB],[EndDate])

I then tried to use int(agevalue) as follows:

        CampAge: Int(DateDiff("yyyy",[DOB],[EndDate]))

This gives me the same result, perhaps because I'm trying to use int with DateDiff

How can I get the calculated age field not to round up?
Would it be better to put this in a function instead of in the query?  


0
Comment
Question by:fernw
  • 2
4 Comments
 
LVL 26

Accepted Solution

by:
EDDYKT earned 500 total points
ID: 16709881
may be use day

DateDiff("d",[DOB],[EndDate]))/365.25
0
 

Author Comment

by:fernw
ID: 16710215
That works.
Thanks!
0
 
LVL 18

Expert Comment

by:deighton
ID: 16716284
that won't always work, you need to do something like

year(enddate) - year(dob) - iif(month(dob)>month(enddate) or month(dob)=month(enddate) and day(dob)>day(enddate),1,0)
0
 

Author Comment

by:fernw
ID: 16717290
I see what you're saying - that if the DOB is in the same month and later than or equal to the enddate, the days/365.25 formula will still give the wrong result (rounded up by 1).  That's probably okay for this application - if a camper turns 10 during the month that camp happens we can say he is 10.  However, for accuracy and general use I would use your formulation.

Sorry I can't award any more points  since I already accepted the other answer- at least I don't think I can. If there's a way to do it, please let me know.

Thanks for your help.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question