Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int DaysTillNextBirthday(DateTime dateOfBirth)
- {
- //full days (whole, 24-hr periods) until next birthday...
- int result = 0;
- DateTime dtToday = DateTime.Now;
- DateTime dtNextBirthday = new DateTime(dtToday.Year, dateOfBirth.Month, dateOfBirth.Day);
- TimeSpan tsDifference = dtNextBirthday - dtToday;
- if (tsDifference.Days < 0)
- {
- //already had birthday this year
- tsDifference = dtNextBirthday.AddYears(1) - dtToday;
- }
- result = tsDifference.Days;
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement