For a computer science assignment I need to calculate how many days it will be until the user turns 18, using their date of birth.
Dim dateToday As Date = Date.Today()
Dim ageNow As Integer = dateToday.Subtract(birthDate).Days
' 6750 is 365 * 18
Dim daysEighteen As Integer = 6750 - ageNow
MsgBox("You will be 18 in " & daysEighteen)
I would use a different method. Add 18 years to the birthdate and then subtract the today date. This should avoid the error implicit in your calculation (365*18 doesn't count the leap years)
Dim birthDate = New DateTime(1999,1,1) Dim adultDate = birthDate.AddYears(18) Console.WriteLine(adultDate.ToString("MM/dd/yyyy")) Dim daysLeft = adultDate.Subtract(DateTime.Today).Days Console.WriteLine(daysLeft)