I am trying to find someones age within 2 months of their birthday on the
given date for the run of the application
Dim d_runOn As DateTime = #4/4/2005#
Dim d_bday As DateTime = #6/26/1986#
Console.WriteLi ne(String.Forma t("Ran on {0}, birthdate {1}",
d_runOn.ToShort DateString, d_bday.ToShortD ateString))
Console.WriteLi ne(String.Forma t("Years difference: {0}",
DateDiff(DateIn terval.Year, d_bday, d_runOn.AddMont hs(2),
FirstDayOfWeek. System, FirstWeekOfYear .System)))
Console.WriteLi ne(String.Forma t("Age of date: {0}",
Math.Floor((Dat eDiff(DateInter val.Day, d_bday, d_runOn.AddMont hs(2),
FirstDayOfWeek. System, FirstWeekOfYear .System) / 365))))
of course the DateInteral.Yea r rounds so even though the person has no
turned 19 yet, it says they are 19. I need it to say they are still 18 years
old (the second one with the Math.Floor / 365 one) gives the correct age
(18). How would i prevent rounding of the DateInterval.Ye ar one?! or is it
even possible?
given date for the run of the application
Dim d_runOn As DateTime = #4/4/2005#
Dim d_bday As DateTime = #6/26/1986#
Console.WriteLi ne(String.Forma t("Ran on {0}, birthdate {1}",
d_runOn.ToShort DateString, d_bday.ToShortD ateString))
Console.WriteLi ne(String.Forma t("Years difference: {0}",
DateDiff(DateIn terval.Year, d_bday, d_runOn.AddMont hs(2),
FirstDayOfWeek. System, FirstWeekOfYear .System)))
Console.WriteLi ne(String.Forma t("Age of date: {0}",
Math.Floor((Dat eDiff(DateInter val.Day, d_bday, d_runOn.AddMont hs(2),
FirstDayOfWeek. System, FirstWeekOfYear .System) / 365))))
of course the DateInteral.Yea r rounds so even though the person has no
turned 19 yet, it says they are 19. I need it to say they are still 18 years
old (the second one with the Math.Floor / 365 one) gives the correct age
(18). How would i prevent rounding of the DateInterval.Ye ar one?! or is it
even possible?
Comment