Tuesday 2 October 2012

How To Create Age Calculator In VB.Net

Download Code # 18

To Create Age Calculator in VB.Net Use Date Function.

Dim dob As DateTime
dob = New DateTime(DTdob.Value.Year, DTdob.Value.Month, DTdob.Value.Day)
Dim tday As TimeSpan = DateTime.Now.Subtract(dob)
Dim years As Integer, months As Integer, days As Integermonths = 12 * (DateTime.Now.Year - dob.Year) + (DateTime.Now.Month - dob.Month)

If DateTime.Now.Day < dob.Day Thenmonths -= 1
days =
DateTime.DaysInMonth(dob.Year, dob.Month) - dob.Day + DateTime.Now.Day
Elsedays = DateTime.Now.Day - dob.Day
End Ifyears = Math.Floor(months / 12)months -= years * 12
Label1.Text =
"Your age as on " & Format(Now, "dd-MMM-yyyy") & _vbCrLf & years &
" Years, " & months & " Months and " & days & " Days"
Output Window


The Above Code Calculate age from Date of Birth to System Date. So Make Sure That System Day is Correct.

No comments:

Post a Comment