Calculate Age using DTPicker (simple code)


Private Sub Command1_Click()
Dim bday As Integer
Dim bmonth As Integer
Dim byear As Integer

bday = DTPicker1.Day
bmonth = DTPicker1.Month
byear = DTPicker1.Year

If Year(Now) <= DTPicker1.Year Then
lblage.Caption = 0
ElseIf (bmonth < Month(Now)) Or (bday < Day(Now)) Then
lblage.Caption = Abs((Year(Now) - DTPicker1.Year) - 1)
Else
lblage.Caption = Abs((Year(Now) - DTPicker1.Year))
End If
End Sub

If you enjoyed this post, subscribe for updates (it's free)