Get programming code snippets and tips for HTML, CSS, ASP, SQL, JavaScript, RSS, XML, and more
Lee's Code        A web programmer's toolbox. SEARCH SITE
HOME  |  ABOUT LEE  |  CONTACT  |  SEARCH
Home > Code > ASP > Calculate a Person's Age

Navigation

Latest Additions

Links


 

Recommendations

Evolve Online
Powered by
Evolve Online
 

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
 

Lee's Code programming tips and tricks. Back to top of page.

Programming tips and tricks for ASP, javaScript, SQL, SML, CSS, HTML HOME | ABOUT LEE | CONTACT | SEARCH
 
Copyright © 2001 - 2010 by Lee A. Shurie