ExtensionMethod.NET Home of 876 C#, Visual Basic, F# and Javascript extension methods


Inspiration for this extension method was another DateTime extension that determines difference in current time and a DateTime object. That one returned a string and it is more useful for my applications to have a TimeSpan reference instead. That is what I did with this extension method.


public static TimeSpan TimeElapsed(this DateTime date)
    return DateTime.Now - date;


var myDate = DateTime.Now;
Console.WriteLine( myDate.TimeElapsed() );
// result -> 00:00:03

Author: jlafay

Submitted on: 3 sep 2010

Language: C#

Type: System.DateTime

Views: 5756