DateTime - Yesterday
A DateTime extension method that returns the yesterday of the given DateTime ofbject.
public static void Main() { DateTime todayDate = DateTime.Now; Console.WriteLine("Current Date : {0}", todayDate.ToFullDateTimeString()); // C# Extension Method: DateTime - Yesterday DateTime tomorrow = todayDate.Yesterday(); Console.WriteLine("After calling Yesterday: {0}", tomorrow.ToFullDateTimeString()); }
View Source
using System; public static partial class Extensions { /// <summary> /// A DateTime extension method that yesterdays the given this. /// </summary> /// <param name="this">The @this to act on.</param> /// <returns>Yesterday date at same time.</returns> public static DateTime Yesterday(this DateTime @this) { return @this.AddDays(-1); } }