Bem vindo ao meu blog, faça comentários ao meu código para tentarmos chegar a uma boa solução

quinta-feira, 12 de julho de 2007

Calcula Idade

Public Function Calcula_Idade(ByVal Birthdate As System.DateTime, Optional ByVal AsOf As System.DateTime = #1/1/1700#) As String
Dim iMonths As Integer
Dim iYears As Integer
Dim dYears As Decimal
Dim lDayOfBirth As Long
Dim lAsOf As Long
Dim iBirthMonth As Integer
Dim iAsOFMonth As Integer
If AsOf = "#1/1/1700#" Then AsOf = DateTime.Now
End If
lDayOfBirth = DatePart(DateInterval.Day, Birthdate)
lAsOf = DatePart(DateInterval.Day, AsOf)
iBirthMonth = DatePart(DateInterval.Month, Birthdate)
iAsOFMonth = DatePart(DateInterval.Month, AsOf)
iMonths = DateDiff(DateInterval.Month, Birthdate, AsOf)
dYears = iMonths / 12
iYears = Math.Floor(dYears)
If iBirthMonth = iAsOFMonth Then
If lAsOf <>
iYears = iYears - 1
End If
End If
Return iYears
End Function

1 comentário:

Anónimo disse...

ler todo o blog, muito bom