This code is inspired a bit by the idea from the php one and implemented in C#, I think you're going to like this kassem:
public static string elapsedTime(DateTime someDate)
{
TimeSpan diff = DateTime.Now.Subtract(someDate);
double totalMin = diff.TotalMinutes;
Dictionary<double, Func<string>> times = new Dictionary<double,Func<string>>();
times.Add(0.75, () => "less than a minute");
times.Add(1.5, () => "about a minute");
times.Add(45, () => string.Format("{0} minutes", Math.Round(totalMin)));
times.Add(90, () => "about an hour");
times.Add(60 * 24, () => string.Format("about {0} hours", Math.Round(Math.Abs(diff.TotalHours))));
times.Add(60 * 48, () => "a day");
times.Add(60 * 24 * 30, () => string.Format("{0} days", Math.Floor(Math.Abs(diff.TotalDays))));
times.Add(60 * 24 * 60, () => "about a month");
times.Add(60 * 24 * 365, () => string.Format("{0} months", Math.Floor(Math.Abs(diff.TotalDays / 30))));
times.Add(60 * 24 * 365 * 2, () => "about a year");
times.Add(double.MaxValue, () => string.Format("{0} years", Math.Floor(Math.Abs(diff.TotalDays / 365))));
return times.First(n => totalMin < n.Key).Value.Invoke() + " ago";
}
I tested the code a bit, it does work but I am not sure if there can be some glitches. If you have questions you can ask, good luck! :)
P.S. I came across
this set of extension methods and they have what you want, check them out :)