Advertisement
kyrathasoft

days till next birthday

May 21st, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.65 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, dateOfBirth.Day);
  7.             TimeSpan tsDifference = dtNextBirthday - dtToday;
  8.  
  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