-2

Program is actually so simple but fails to execute when I enter a date like 09/21/1993. A person who's born on that date is obviously under 25 but output is "YES" because of 2018-1993=25. How do I prevent that?

dateOfBirth = CDate(txtBirth.Text)
a = (DateDiff(DateInterval.Year, dateOfBirth, Today))
If a < 25 Then
    txt25.Text = "NO"
Else
    txt25.Text = "YES"
GSerg
  • 76,472
  • 17
  • 159
  • 346
  • @Plutonix I don't think that is a duplicate. Calculating number of days between two dates is not enough to [calculate someone's age](https://stackoverflow.com/q/9/11683). – GSerg May 06 '18 at 08:39

1 Answers1

0

Ok I just figured out.

    dateOfBirth = CDate(txtBirth.Text)
    b = dateOfBirth.AddYears(25)
    a = CInt(DateDiff(DateInterval.Day, Today, b))
    If a < 0 Then
        txt25.Text = "NO"
    Else
        txt25.Text = "YES"