Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

The age of a person

Total Hit ( 2846)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


You can quickly evaluate the age of a person using the following function:

Click here to copy the following block
Function Age(BirthDate As Date, Optional CurrentDate As Variant) As Integer
  If IsMissing(CurrentDate) Then CurrentDate = Now
  Age = Year(CurrentDate) - Year(BirthDate)
End Property

If you omit the second argument, the age is evaluate at the current time, but specifying it you can evaluate the age at any given date.
The above function, however, evaluates the age of a person in a "informal" way. To see what this means, run the following code:

Click here to copy the following block
Print Age(#6/1/1980#, #1/1/2000#)   ' returns 20

It is evident that the function actually returns the age of the person on his/her birthday in the current year, but the actual age could be less than this value. To evaluate the "exact" age, use the following variant:

Click here to copy the following block
Function Age(BirthDate As Date, Optional CurrentDate As Variant, _
  Optional ExactAge As Boolean) As Integer
  If IsMissing(CurrentDate) Then CurrentDate = Now
  Age = Year(CurrentDate) - Year(BirthDate)
  
  If ExactAge Then
    ' subtract one if this year's birthday hasn't occurred yet
    If DateSerial(Year(CurrentDate), Month(BirthDate), _
      Day(BirthDate)) > CurrentDate Then
      Age = Age - 1
    End If
  End If
End Property


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.