DateTime - IsPast

A DateTime extension method that query if '@this' is in the past.

Try it

public static void Main()
{
    DateTime date1 = DateTime.Now.AddYears(2);
	DateTime date2 = new DateTime(2006, 7, 25, 10, 45, 09);
	
	Display(date1);
	Display(date2);
}

public static void Display(DateTime date)
{
	// C# Extension Method: DateTime - IsPast
	if(date.IsPast())
	{
		Console.WriteLine("{0, 40}: It's a past date.", date.ToFullDateTimeString());
	}
	else
	{
		Console.WriteLine("{0, 40}: It's not a past date.", date.ToFullDateTimeString());
	}
}

View Source
using System;

public static partial class Extensions
{
    /// <summary>
    ///     A DateTime extension method that query if '@this' is in the past.
    /// </summary>
    /// <param name="this">The @this to act on.</param>
    /// <returns>true if the value is in the past, false if not.</returns>
    public static bool IsPast(this DateTime @this)
    {
        return @this < DateTime.Now;
    }
}