to calculate age of a person when a date from date time picker was selected

Posted on 2006-04-24
Medium Priority
Last Modified: 2007-12-19
i've a date time picker used to enter date of birth of a person.there is also a textbox named 'txtage', to calculate the age of a particular person.

when i select a date from the date time picker, i want to automatically calculate and display the age in the 'txtage' textbox. how i do that?
Question by:lincyelias
1 Comment
LVL 43

Accepted Solution

TimCottee earned 120 total points
ID: 16523440
Hi lincyelias,

    Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
        Dim Years As Double = DateDiff(DateInterval.Month, DateTimePicker1.Value, Now()) / 12
        Dim Months As String = Int(DateDiff(DateInterval.Month, DateTimePicker1.Value, Now())) - Int(Years) * 12
        If Years < 0 Or Months < 0 Then
            TextBox1.Text = "Not yet born!!!"
            TextBox1.Text = Int(Years) & " Years, " & Months & " Months"
        End If
    End Sub

For example

Tim Cottee

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question