Results 1 to 4 of 4

Thread: Calculating the age of a person in years, months and days

  1. #1
    Guest

    Question Calculating the age of a person in years, months and days

    Dear Sir/Madam

    I am using access 97 and would want a visual basic function that I can use to enter(Calculate) the age of a person based on the date of birth and the current date, that is in a text box.

    Gots

  2. #2
    Lively Member Patrice Bourdages's Avatar
    Join Date
    Jun 2000
    Location
    Quebec, Canada
    Posts
    83

    Smile

    Have you tried something like the following:

    Code:
    public function age(DateOfBirth) as integer
       age = ((date() - DateOfBirth) / 365.25)
    end function
    I use something similar in some of my programs. You could modify it to check if DateOfBirth is really a date, modify the results (the formatting) or whatever.

    Hope this helps...

    Sincerely yours,

    Patrice B.
    Information System Analyst
    SAS 9.1.3, VB6 SP6, VB.Net 2003, SQL7.0/2000

  3. #3
    New Member
    Join Date
    Oct 2000
    Location
    Hyderabad (INDIA)
    Posts
    6

    Thumbs up Very simple!!! Calculating age in years,months,days

    pryear = Year of today's date
    prmonth = Month of today's date
    prday = Day number of today's date
    psyear = Year of Past date
    psmonth = Month of Past date
    psday = Day number of Past date


    1.First check today's date is greater than Entered date.
    2.Calculate totyears=pryear-psyears
    3.check psmonth<prmonth
    if yes
    totyears=totyears-1
    totmonths=(12-psmonth+prmonth)
    if no
    totmonths=prmonth-psmonth
    4.check psday<prday
    if yes
    {
    check totmonths=0
    if yes
    totyears=totyears-1
    totmonths=11
    if no
    totmonths=totmonths-1
    totdays=(30-psday+prday)
    }
    if no
    totdays=prday-psday

    5.Display output :
    totyears & " years " & totmonths & " months " & totdays & " days"



  4. #4
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Brooklyn NY USA
    Posts
    1,258
    use the following code

    Code:
    YourDte = Cdate("TextBox??")
    
    Days = Date - YourDte
    Years = Days / 365

Posting Permissions

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



Click Here to Expand Forum to Full Width