VB.NET - Calculate age from birthdate @JFLHV
VB.NET - Calculate age from birthdate  @JFLHV
Uploaded January 2020 | Updated September 2026, 1 week ago
VB.Net code to determine a person's age from birthdate using the date diff function.

Visual Studio Community 2017
.NET Framework 4.6.1
Windows 10

#vbdotnet

Code below.
'Angled brackets not allowed so replace "GREATER_THAN'

'Calculate age from birthdate
Private Function Age(ByVal birthdate As DateTime) As String

Dim ageDays As Integer
Dim ageMonths As Integer
Dim ageYears As Integer

ageDays = DateDiff("d", birthdate, Now)
ageMonths = DateDiff("m", birthdate, Now)

'Reduce month by 1 if birthdate day not yet reached
If birthdate.Day GREATER_THAN Now.Day Then
ageMonths = ageMonths - 1
End If

'Calculate years (Do not round value up)
ageYears = Math.Truncate(ageMonths / 12) 'can use \ operater as well

If ageYears GREATER_THAN 0 Then
Return ageYears.ToString + Plural(ageYears, " Year")
ElseIf ageMonths GREATER_THAN 0 Then
Return ageMonths.ToString + Plural(ageMonths, " Month")
Else
Return ageDays.ToString + Plural(ageDays, " Day")
End If

End Function

'Return plural form of text if value not = 1
Private Function Plural(value As Integer, text As String)
If Math.Abs(value) = 1 Then
Return text
Else
Return text + "s"
End If
End Function
VB.NET - Calculate age from birthdateMotion tracking tips iMovie macOSGet Google Pixel Settings Sound FileVB.NET - Multiple series chart populated manuallyCustom split screen iMovie macOSChange Google Maps directions walking to drivingC# - How my automation app worksVertical camera recording overlay demoC# - .NET JSON User SettingsShow music controls Pixel 4Hand-drawn circle green screenMy Weathertop star solution Talos Principle
JFLHV |

VB.NET - Calculate age from birthdate

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER