0

compare birthdays and todays date c#

I have a code to compare a birthday to todays date and it can tell you how old you are in years, but I can't get it to tell me the right amount of days. ex you are x years and y days old. The days old is always wrong. I tried using my timespan variable old.totaldays % 365 and that is off by 4 - 5 days every time. any advice would be great.

24th Sep 2018, 3:38 PM
David Aseltine
David Aseltine - avatar
6 Réponses
+ 5
You could forget about leap years. Each 4 years it should add 1 day.
24th Sep 2018, 4:06 PM
Aleksander Szczepura
Aleksander Szczepura - avatar
+ 3
Check for how many leap year there are in between current year and the birth year. Then just add the number of years with the number of days.
24th Sep 2018, 4:31 PM
Akib
Akib - avatar
+ 1
ok Ill give that a try thank you
24th Sep 2018, 4:37 PM
David Aseltine
David Aseltine - avatar
+ 1
after doing that it works perfectly thank you
24th Sep 2018, 5:02 PM
David Aseltine
David Aseltine - avatar
+ 1
Glad i could help. Happy coding🙂.
25th Sep 2018, 4:24 AM
Akib
Akib - avatar
0
ok that make sense how could I fix that?
24th Sep 2018, 4:24 PM
David Aseltine
David Aseltine - avatar