S
H
A
R
E

Monday, July 11, 2011

How To Calculating Human Age

Using VB .net, Make a Windows Form Application, And use one DateTimePicker control, and write this code:


Private Sub DateTimePicker1_ValueChanged() Handles DateTimePicker1.ValueChanged
  Dim Birth As Date = DateTimePicker1.Value
  Dim year, month, day As Integer
  While year <= (Now.Year - Birth.Year)

     While month <= (Now.Month - Birth.Month)
       While day <= (Now.Day - Birth.Day)
         day += 1
       End While
       month += 1
     End While
     year += 1
  End While
  year -= 1 : month -= 1 : day -= 1
  TextBox1.Text = year & " year " & month & " month " & day & " day"
End Sub

Try this code to calculate your age

1 comments:

Saqib Sabir said...

hahahah nice but not working properly. You cant calc your age with this if your birthday was not past away. check it again :-)
i.e: my date birth is 26/8/1990
and
today is 5/2/2013 (d/m/yyyy)
this will return 23 Years & -1 month and -1 days. It's wrong obviously.
output should be = 22 Years & 6 Months & some days. etc

Post a Comment