LengthOfTime
return the length of time between the start and current date
Source
public static string LengthOfTime(this DateTime date)
{
TimeSpan lengthOfTime = DateTime.Now.Subtract(date);
if (lengthOfTime.Minutes == 0)
return lengthOfTime.Seconds.ToString() + "s";
else if (lengthOfTime.Hours == 0)
return lengthOfTime.Minutes.ToString() + "m";
else if (lengthOfTime.Days == 0)
return lengthOfTime.Hours.ToString() + "h";
else
return lengthOfTime.Days.ToString() + "d";
}
Example
lastActivityDate.LengthOfTime();