Calculated age field rounding up

Posted on 2006-05-18
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?  

Question by:fernw
    LVL 26

    Accepted Solution

    may be use day


    Author Comment

    That works.
    LVL 18

    Expert Comment

    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)

    Author Comment

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Title # Comments Views Activity
    Swap listbox items in VB6. 4 36
    z = x + y – 1 6 48
    Pull multiple cvs files into one access table 28 52
    MsgBox 2 27
    There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
    Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    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…

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now