Generate age from a datetimepicker

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • danielokk
    New Member
    • Feb 2008
    • 1

    Generate age from a datetimepicker

    Can someone Plz help me build my application ?
    I mean how can I Auto Generating Age in a textbox using datetimepicker in VB code plz.
  • QVeen72
    Recognized Expert Top Contributor
    • Oct 2006
    • 1445

    #2
    Hi,

    You mean to say, you use DateTime Picker for Date of Birth,
    and after selecting want to show age in textbox..?

    REgards
    Veena

    Comment

    • jamesd0142
      Contributor
      • Sep 2007
      • 471

      #3
      Originally posted by QVeen72
      Hi,

      You mean to say, you use DateTime Picker for Date of Birth,
      and after selecting want to show age in textbox..?

      REgards
      Veena
      find todays date and the date selected in dateTime picker then use

      datdiff() function to work out age.

      Comment

      • mafaisal
        New Member
        • Sep 2007
        • 142

        #4
        Hello

        Try this

        Code:
        Private Function GetAge(DOB As Date) As Integer
        Dim Age As Integer
        If DOB > Date Then GetAge = 0: Exit Function
        Age = Year(Date) - Year(DOB)
        If Month(DOB) > Month(Date) Or (Month(DOB) = Month(Date) And Day(DOB) > Day(Date)) Then
         Age = Age - 1
        End If
        GetAge = Age
        End Function
        Using Thsese Function U Can Get Age
        Here DOB is Date
        Use DTPicker is To set DateofBirth

        Faisal

        Originally posted by danielokk
        Can someone Plz help me build my application ?
        I mean how can I Auto Generating Age in a textbox using datetimepicker in VB code plz.

        Comment

        Working...