VB 6.0 - how to compute age? - Asked By Ralph Acido on 28-Feb-06 08:47 PM

hello everyone! anyone who have an idea on how to compute the age of a person base from the date of birth and the current date in decimal format? e.g.(8.5, 7.75, 5.25) thank you in advance...

SQL Query - Asked By drammer _ on 28-Feb-06 10:33 PM

select ROUND((DATEDIFF(d, dateField, getdate()) / 365.25), 0, 1)+((DATEDIFF(d, dateField, getdate()) %  365)/30)/12.0 from yourTable

see this function - Asked By Venkat K on 28-Feb-06 10:35 PM

[CODE]
Public Function GetAccurateAge(ByVal dtefrom As Date, _
   ByVal dteto As Date) As Integer
On Error GoTo ErrHandler
   Dim intFromDay As Integer, intFromMon As Integer, intFromYr As Integer
   Dim intToDay As Integer, intToMon As Integer, intToYr As Integer
   Dim intResultAge As Integer
    
   intFromYr = Year(dtefrom)
   intFromMon = Month(dtefrom)
   intFromDay = Day(dtefrom)
   
   intToYr = Year(dteto)
   intToMon = Month(dteto)
   intToDay = Day(dteto)
   
   If intFromYr <= intToYr Then
      intResultAge = intToYr - intFromYr
   Else
      GetAccurateAge = -1: Exit Function ' invalid value
   End If
   
   If intFromMon <= intToMon Then
         If (intFromMon = intToMon) And (intFromDay > intToDay) Then
            intResultAge = intResultAge - 1
         Else
            intResultAge = intResultAge
         End If
   Else
      intResultAge = intResultAge - 1
   End If
   GetAccurateAge = intResultAge
      
GetAccurateAgeExit:
   Exit Function
   
ErrHandler:
   GetAccurateAge = -1
End Function
[/CODE]

your program is working but? - Asked By Ralph Acido on 01-Mar-06 12:09 AM

thank you.. your program is really working.. it returns the accurate age in a whole number... what im lookig for is the age should be in a floating point format.. e.g(7.5, 8.25 like that...)