Aqueduct.Extensions.Dates.TimeDiff C# (CSharp) Method

TimeDiff() public static method

Displays the difference in time between the two dates. Return example is "12 years 4 months 24 days 8 hours 33 minutes 5 seconds"
public static TimeDiff ( this startTime, System.DateTime endTime ) : string
startTime this The start time.
endTime System.DateTime The end time.
return string
        public static string TimeDiff(this DateTime startTime, DateTime endTime)
        {
            int seconds = endTime.Second - startTime.Second;
            int minutes = endTime.Minute - startTime.Minute;
            int hours = endTime.Hour - startTime.Hour;
            int days = endTime.Day - startTime.Day;
            int months = endTime.Month - startTime.Month;
            int years = endTime.Year - startTime.Year;
            if (seconds < 0)
            {
                minutes--;
                seconds += 60;
            }
            if (minutes < 0)
            {
                hours--;
                minutes += 60;
            }
            if (hours < 0)
            {
                days--;
                hours += 24;
            }
            if (days < 0)
            {
                months--;
                int previousMonth = (endTime.Month == 1) ? 12 : endTime.Month - 1;
                int year = (previousMonth == 12) ? endTime.Year - 1 : endTime.Year;
                days += DateTime.DaysInMonth(year, previousMonth);
            }
            if (months < 0)
            {
                years--;
                months += 12;
            }

            string sYears = FormatString(YEAR, String.Empty, years);
            string sMonths = FormatString(MONTH, sYears, months);
            string sDays = FormatString(DAY, sMonths, days);
            string sHours = FormatString(HOUR, sDays, hours);
            string sMinutes = FormatString(MINUTE, sHours, minutes);
            string sSeconds = FormatString(SECOND, sMinutes, seconds);

            return String.Concat(sYears, sMonths, sDays, sHours, sMinutes, sSeconds);
        }