Blogia
Christian Torres

Calcular edad cronologica

Les comparto estas 2 funciones teniendo como principal a la funcion calculo_e

La invocacion seria asi:    DIM S as string =calculo_e(fecha_nacimiento, fecha_hoy)

 

 

 

 

 

 

 

Function dias_mes(ByVal n As Integer, ByVal a As Integer) As

Long

 

Select Case n

 

Case 1, 3, 5, 7, 8, 10, 12

dias_mes = 31

 

Case 4, 6, 9, 11

dias_mes = 30

 

Case 2

 

If (a Mod 4) = 0 Then
 

dias_mes = 29

Else

dias_mes = 28

 

End If

 

Case

Else

dias_mes = 0

 

End Select

 

End Function

 

Function calculo_e(ByVal fn As Date, ByVal fh As Date) As

String

 

Dim dd As

Integer

 

Dim mm As

Integer

 

Dim yy As

Integer

 

Dim da As

Integer

 

Dim ma As

Integer

 

Dim ya As

Integer

 

Dim d As

Integer

 

Dim m As

Integer

 

Dim y As

Integer

dd = fn.Day

da = fh.Day

mm = fn.Month

ma = fh.Month

yy = fn.Year

ya = fh.Year

 

If da < dd Then
 

da = da + dias_mes(ma, ya)

ma = ma - 1

 

End If

If ma < mm

Then

ma = ma + 12

ya = ya - 1

 

End

If

d = da - dd

m = ma - mm

y = ya - yy

 

Return (y & " AOS" & "CON " & m & " MESES" & "Y " & d & " DIAS")

End

Function

 

 

0 comentarios