VB icon

GetAGE Function

Email
Submitted on: 1/6/2015 6:48:00 PM
By: Randy McCleary (from psc cd)  
Level: Intermediate
User Rating: By 5 Users
Compatibility: ASP (Active Server Pages)
Views: 876
 
     This is just a Simple little ASP Script Function that can be used to get the AGE of a person, object, anniversary, or whatever you would like to find out how old something is in YEARS.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: GetAGE Function
' Description:This is just a Simple little ASP Script Function that can be used to get the AGE of a person, object, anniversary, or whatever you would like to find out how old something is in YEARS.
' By: Randy McCleary (from psc cd)
'
' Inputs:A validate Date
'
' Returns:An Interger Value of the AGE in years, or a String "NULL" if an invalid date was input.
'
' Assumes:Notes: Calculation of a year is based upon
 the most accurate formula which states
 a Year = 365.242222 Days(Tropical Season). 
 An error of 1 day will occur every 40,000
 years with this formula.
If the Julian formula is used then
 A Year = 365.25 days, which means every 
 128 years an Error of 1 Day will occur.
If the Gregorian formula is used then
 A Year = 365.2425, which is fairly accurate
 But every 3200 years an Error of 1 day will
 occur.
'**************************************

<% @ LANGUAGE = VBScript %>
<% Option Explicit %>
<%
'##############################################
'## Function Name: GetAGE()
'## 
'## Description: This function will take an
'## input date and calculate the age in years
'## of how old someone is or age of an item
'## to the current Date.
'##
'## Inputs: A valid date ex: 04/25/2000
'##
'## Returns: Integer - AGE in YEARS
'## NULL If invalid input 
'##
'## Notes: Calculation of a year is based upon
'##the most accurate formula which states
'##a Year = 365.242222 Days(Tropical Season). 
'##An error of 1 day will occur every 40,000
'##years with this formula.
'##
'## If the Julian formula is used then
'##A Year = 365.25 days, which means every 
'##128 years an Error of 1 Day will occur.
'##
'## If the Gregorian formula is used then
'##A Year = 365.2425, which is fairly accurate
'##But every 3200 years an Error of 1 day will
'##occur.
'##############################################
Function GetAGE(dtmDate)
	Dim intAGE
	
	If IsDate(dtmDate) <> True Then
		GetAGE = "NULL"
		Exit Function
	End If
	 
	intAGE = DateDiff("d", dtmDate, Date)
	Response.Write "AGE is " & intAGE & "<br>"
	
	If IsNumeric(intAGE) Then
		intAGE = Int(Round(Abs(intAGE) / 365.242222, 4))
	End If
	GetAGE = intAGE
End Function
'----------------------------------
Dim dtmDate
dtmDate = "4/24/1875"
Response.Write "AGE is " & GetAGE(dtmDate) & "<br>"
%>


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.