c# - Simplest way to calculate anniversary given a date in the past? -
I need a function which calculates that if a person has a date of the beginning of the current and present date For an upcoming anniversary. I got this code below, but by looking at the code given below and I'm feeling this is a very easy way to calculate it without loop:
personal const int ANNIVERSARY_ALERT = 10; Public virtual string upcoming milestones {{var years = years (+ 2); (Int year = 0; year> year; year ++) {int day = year * 365; Int diefiff = day - numberofday; If (Didiff == 0) {return year + "year landmark"; } If (Dediff & lt; ANNIVERSARY_ALERT & amp; Daydiff & gt; 0) {Return Year + "Day Def +" "Landmark" Day; }} Return string Empty; }} Public Virtual Entomophage {get {timeSpan ts = DateTime.Today - StartDate.Value; Return (int) ts shielded; }} Public Virtual Favourited (Year) (Time Span Span = DateTime.Now Subtract .Valil; Return (int) (span.Days / 365.25); // leap years included} < P> Can anyone recommend this loop without the need to calculate it above? This is more for code maintenance compared to the views of any display.
Use related parts of start date New date:
// My birthday, up Feel free to enter this date in the calendar! Var startDate = New date time (1976, 2, 29); // Date of anniversary for this year Date time Next federation; Try {Next Anniversary = New Date Time (Date Time Today, Beginning, Death, Start.) (ArgumentOutOfRangeException) {// DateTime conversion failed, try next year next year = Rewind date = new date, date today, year, start day. Add Day (1). Death Start, add. (1) .days);} // Check whether this year's anniversary has already happened (if the next embodiment and date; Date time Today) Next character = Next Parliament. Extra years (1);
Comments
Post a Comment