
| Navigation |
|
|
 |
| Latest Additions |
|
|
 |
| Links |
|
 |
| Recommendations |
|
 |
|
Calculate a Person's Age
By: Lee A. Shurie |
| Subject: |
Calculate Age |
| Language: |
ASP |
| Rating: |
 Rated 31 times. Rate or review this item: 1 2 3 4 5 Read Reviews
|
See it in action |
Information How do you calculate a person's age in ASP?
You might think the DateDiff function would work if you use the year (yyyy) option. But it doesn't work right because it simply compares the starting year and the ending year without considering the month and day. We have to perform a little trick to modify the result of the DateDiff function. We do this by testing to see if the month and day of birth are later in the year than today's month and day. If so, we subtract a year. |
Code
|
Instructions Copy the function to your ASP page. Then call it by seting a value for the variable DateOfBirth and then call the function like this:
UsersAge = CalculateAge(DateOfBirth)
You don't actually need all of the code displayed here. I have included a simple form to demonstrate the function, but to calculate the person's age you only need the function itself. |
Keywords:calculate age ASP code function |
|

|