|
-
Oct 4th, 2000, 11:00 AM
#1
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
-
Oct 4th, 2000, 11:30 AM
#2
Lively Member
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
-
Oct 4th, 2000, 11:53 AM
#3
New Member
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"
-
Oct 4th, 2000, 08:05 PM
#4
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|