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

Posted on 2006-04-24
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 44

    Accepted Solution

    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now