New call-to-action
Results 1 to 5 of 5

Thread: Age Calculation

  1. #1
    Guest
    Real Name
    Mike Gorom
    Join Date
    Sep 2004
    Posts
    22

    Default Age Calculation

    I'm sure this has been asked many times before but if someone could help... What would the formula look like to calculate AGE from Today's Date and a Birthdate and have it return Years & Months... i.e. 11 years 4 months old.

  2. #2
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,317

    Default RE: Age Calculation


    Years:
    age(birthdate, date()) would give you the years

    Months:
    if(month(date()) - month(birthdate)"= 0, month(date()) - month(birthdate), month(date()) - month(birthdate) + 12)


    Looks like a two step script to me. Don't know of a way to do it in a single statement.

    -- tom

  3. #3
    "Certified" Alphaholic
    Real Name
    Michael Humby
    Join Date
    Apr 2000
    Location
    Leicester, UK
    Posts
    1,036

    Default RE: Age Calculation

    This is the calc that I use, there may be a better solution.

    STR(INT((DATE()-DOB)/30.4167/12),2)+":"+STR(MOD(INT((DATE()-DOB)/30.4167),12),2)

    Michael

  4. #4
    Guest
    Real Name
    Mike Gorom
    Join Date
    Sep 2004
    Posts
    22

    Default RE: Age Calculation

    I'll give it a try. Thanks Very Much!

    Mike

  5. #5
    VAR davej's Avatar
    Real Name
    Dave Jampole
    Join Date
    Apr 2000
    Location
    Haughton, LA ( just east of Shreveport, Louisiana)
    Posts
    2,524

    Default RE: Age Calculation

    Mike,

    Here is a function that I got from Charles Hoens and with a slight change, it returns exactly what you want - even the years and months are singular when there is only one.

    'Date Created: 21-Feb-2003 02:43:35 PM
    'Last Updated: 24-Aug-2004 10:49:24 AM

    FUNCTION ChildAge AS C (DOB AS D )
    dim fyear1 as n
    dim fyear2 as n
    dim fmonth1 as n
    dim fmonth2 as n
    dim yearage as n
    dim mosage as n
    dim totmos as n
    dim newyears as n
    dim newmos as n
    dim cyrs1 as c
    dim cmos1 as c

    fyear1=year(DOB)
    fyear2=year(date())
    fmonth1=month(DOB)
    fmonth2=month(date())

    yearage=(fyear2-fyear1)*12
    mosage=fmonth2-fmonth1

    totmos=yearage+mosage
    newyears=int(totmos/12)
    newmos=totmos-newyears*12

    if newyears = 1
    cyrs1 = "Year"
    else
    cyrs1 = "Years"
    end if
    if newmos = 1
    cmos1 = "Month"
    else
    cmos1 = "Months"
    end if

    ChildAge=alltrim(str(newyears))+" "+cyrs1+", "+alltrim(str(newmos))+" "+cmos1

    END FUNCTION

    Dave

Similar Threads

  1. Age Calculation
    By Paul Reese in forum Alpha Five Version 5
    Replies: 5
    Last Post: 01-30-2003, 09:46 AM
  2. Age Calculation
    By Brett Heintzman in forum Alpha Five Version 4
    Replies: 6
    Last Post: 01-27-2003, 04:57 PM
  3. Calculation Help
    By Bill Griffin in forum Alpha Five Version 4
    Replies: 1
    Last Post: 10-20-2001, 09:16 AM
  4. Need help with calculation
    By Wanda Friesen in forum Alpha Five Version 4
    Replies: 2
    Last Post: 08-16-2000, 08:26 AM
  5. If/then calculation in a set
    By Wanda Friesen in forum Alpha Five Versions 2 and 3
    Replies: 0
    Last Post: 06-01-2000, 10:20 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •