Una función en VB para asp.net que calcula la edad
4 marzo, 2015
Por: Editor PGBServices

‘******************* PARA CALCULAR EDAD EN AÑOS…..PIERRE
Public Shared Function calcularEdad(ByVal fechaNacimiento As Object, Optional ByRef mesesCumplidos As Integer = 0) As Integer

Dim añosCumplidos As Integer = 0
Dim fechaActual As New Date(Date.Now.Year, Date.Now.Month, Date.Now.Day)

Try

If Not IsDBNull(fechaNacimiento) Then

If IsDate(fechaNacimiento) Then

If DateAndTime.DateDiff(DateInterval.Day, fechaNacimiento, fechaActual) > 0 Then
Dim valorDecimal As Decimal = 0
valorDecimal = DateDiff(DateInterval.Month, fechaNacimiento, Now) / 12
añosCumplidos = Decimal.Truncate(valorDecimal)
valorDecimal = (valorDecimal – añosCumplidos) * 12
mesesCumplidos = Decimal.Truncate(valorDecimal)

If Month(fechaNacimiento) = Now.Month Then
If Day(fechaNacimiento) > Now.Day Then
añosCumplidos -= 1
End If
End If

If añosCumplidos < 0 Then
añosCumplidos = 0
End If

End If

End If

End If

Catch ex As Exception

añosCumplidos = 0
Exit Try
End Try

Return añosCumplidos

End Function

Hosting mejor precio valor para tu Web

Reserva de dominio

VPS

Correos

Asistencia

Instalación de CMS incluido

Ver más: https://espro.es

 

Share This