joshua joshua - 1 year ago 100 Question

compute age from given birthdate

I have 2 comboboxes and 2 textboxes. My first combobox contains months in this format january, february, etc, and the other combobox contains numbers from 1 to 31. My first textbox is

. Once the user input birth year to
a variable
will be equals to this.

Dim BOD as string
BOD = cbomonth.text + "-" + cboday.text + "-" + txtyear.text

The purpose of my last textbox is to handle the age of the user that will be computed when the cursor lost focus on

Can anyone help how to compute the age.

Answer Source

There are really two questions here:

  1. How to convert the string input into a DateTime object
  2. How to calculate age once you have your data in the correct format.

I'll let you follow other's instructions for how use TryParseExtract which is definitely the correct way to go here.

When determining someone's age from their DOB, try using this:

Public Function GetCurrentAge(ByVal dob As Date) As Integer
    Dim age As Integer
    age = Today.Year - dob.Year
    If (dob > Today.AddYears(-age)) Then age -= 1
    Return age
End Function

It is the vb version of the top answers on Jeff Atwood's very popular question How do I calculate someone's age

I wrote a blogpost about calculating age from dob as well.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download