Results 1 to 14 of 14
  1. #1
    bmiller310 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    6

    Age Calculation

    I've used a formula to calculate age in a query. The only formula that works is one that uses the "now" feature. I want to calculate the age of a person based on a defined date. For example: I need to know how old a person is on or before May 1, 2012. This is a youth athletic association so it has to be precise. We usually print registration information in January. This formula works, but I'm not sure where to put "5/1/2012". Thanks.

    CalAge: DateDiff("yyyy",[DOB],Date())+(Date()<DateSerial(Year(Date()),Month([DOB]),Day([DOB])))

  2. #2
    bigroo's Avatar
    bigroo is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jan 2012
    Location
    Austin, Texas
    Posts
    101

    Age Calculation

    Hi bmiller310,

    I will take a guess and say place 05/01/2012

    CalAge: DateDiff("yyyy",[DOB],Date())+(Date()<DateSerial(Year(Date()),Month([DOB]),Day([DOB])))

    Here:

    CalAge: DateDiff("yyyy",[DOB],#05/01/2012#)+(Date()<DateSerial(Year(Date()),Month([DOB]),Day([DOB])))

    Someone correct me if I am wrong!!

  3. #3
    bmiller310 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    6
    I just tried that. It still calculates using the current date. Any other suggestions.

  4. #4
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071
    Change it to
    DateDiff("yyyy",,[dob],#05/01/2012#)+(#05/01/2012#>DateSerial(Year(Date()),Month([dob]),Day([dob])))

  5. #5
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071
    Although the #05/01/2012# should actually be CVDate("05/12/" & Year(date())) That way you don't have to change it each year.

  6. #6
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    If this is for some event: tournament, race, etc., you probably have the date of the event stored somewhere. You could reference that date in the age calculation, in case you have multiple events during the year.

  7. #7
    bigroo's Avatar
    bigroo is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jan 2012
    Location
    Austin, Texas
    Posts
    101

    Age Calculation

    Thanks RayMilhon,

    I did not see the second Date() reference in the formula!!
    Thanks

  8. #8
    bmiller310 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    6
    Thanks guys, this works great. If I had an event date called EDate where would I put it in the formula.

  9. #9
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071
    The later date should be second. If the later date is first you will get a negative number

    For example

    DateDiff("d", #11/01/2011#, #11/02/2011#) = 1
    DateDiff("d",#11/02/2011#, #11/01/2011#) = -1

  10. #10
    bmiller310 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    6
    Found another problem with this formula:

    When the DOB is 1/2/2000 and I use the formula:

    CalAge: DateDiff("yyyy",[dob],#5/1/2012#)+(#5/1/2012#>DateSerial(Year(Date()),Month([dob]),Day([dob])))
    I get an answer of 11 instead of 12. Any suggestions?

  11. #11
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071
    Here's what's happening.
    DateDiff("yyyy",[dob],#05/01/2012#) = 12
    #05/01/2012#>DateSerial(Year(date()),Month([dob]),Day([dob]))) = True = -1
    12+(-1)=11

    What you're statement says is if the date 05/01/2012 Is > the persons birthday subtract 1 from the age.

  12. #12
    bmiller310 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    6
    So I guess I should change the second part to say "month"??? I'm not sure here. Thanks.

  13. #13
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071
    First let's look at the 2 possibilites

    1. DOB = 1/2/2000
    2. DOB = 12/2/2000

    Case 1 their age on 05/01/2012 is 12
    Case 2 their age on 05/01/2012 is 11

    Part 1 of the formula
    Datediff("yyyy",[dob],#05/01/2012#)

    Case 1 = 12 should be True
    Case 2 = 12 should be false

    2nd part of the formula
    +(#05/01/2012>DateSerial(Year(date()),Month([dob]),Day([dob]))))

    Case 1 Dateserial(Year(date()),MOnth([dob]),Day([dob])) = DateSerial(2012,1,2) so the formula = (#05/01/2012#>#01/02/2012#) = True = -1

    Case 2 Dateserial(Year(date()),MOnth([dob]),Day([dob])) = DateSerial(2012,12,2) so the formula = (#05/01/2012#>#12/02/2012#) = False = 0

    Results
    Case 1 = 12 + (-1) = 11
    Case 2 = 12 + 0 = 12

    So the Correct formula is

    CalAge: DateDiff("yyyy",[dob],#5/1/2012#)+(#5/1/2012#<DateSerial(Year(Date()),Month([dob]),Day([dob])))

  14. #14
    bmiller310 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    6
    I think I figured it out. It's a little different formula, but I think it works:

    CalAge: DateDiff("yyyy",[DOB],#9/1/2012#)-IIf(Format([DOB],"mmdd")>Format(#9/1/2012#,"mmdd"),1,0)

Please reply to this thread with any new information or opinions.

Similar Threads

  1. BMI calculation
    By puush in forum Programming
    Replies: 9
    Last Post: 08-19-2014, 05:05 AM
  2. Calculation
    By buienxg in forum Access
    Replies: 1
    Last Post: 11-16-2011, 07:20 AM
  3. How to do calculation???
    By latestgood in forum Forms
    Replies: 0
    Last Post: 05-18-2011, 11:11 AM
  4. value calculation
    By kyle in forum Access
    Replies: 3
    Last Post: 03-06-2011, 12:29 PM
  5. Calculation Help
    By ErnieS in forum Access
    Replies: 13
    Last Post: 07-08-2010, 08:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums