TimeDiff

Contents

Namespace

SubSonic.Extensions.Dates

Summary

Displays the difference in time between the two dates. Return example is "12 years 4 months 24 days 8 hours 33 minutes 5 seconds

Example

string output=Post.PublishedDate.TimeDiff(DateTime.Now);

Unit Test

public void TimeDiff_Should_Say_3_Days_8_Hourse_5Minutes_3Seconds_Ago_When_DateTimeNow_Is_Diffed_WithAddedValues() {
    var today = DateTime.Now;
    var then = DateTime.Now.AddDays(3).AddHours(8).AddMinutes(5).AddSeconds(2);
    var diff = today.TimeDiff(then);
    Assert.Equal("3 days 8 hours 5 minutes 2 seconds ", diff);
 
}

Comments

SubSonic 3.0 implements this as an extension on System.DateTime - 2.x uses a static method on SubSonic.Sugar.Dates.