Advertisement
kyrathasoft

Days Till Next Birthday

May 21st, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.51 KB | None | 0 0
  1. public static int DaysTillNextBirthday(DateTime dateOfBirth) {
  2.  
  3.   //full days (whole, 24-hr periods) until next birthday...
  4.   int result = 0;
  5.   DateTime dtToday = DateTime.Now;
  6.   DateTime dtNextBirthday = new DateTime(dtToday.Year, dateOfBirth.Month,
  7.       dateOfBirth.Day);
  8.   TimeSpan tsDifference = dtNextBirthday - dtToday;
  9.   if (tsDifference.Days < 0)
  10.   {
  11.       //already had birthday this year
  12.       tsDifference = dtNextBirthday.AddYears(1) - dtToday;
  13.   }
  14.   result = tsDifference.Days;
  15.   return result;
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement