Will give you the DateTime object given the number of days you go back. - CSharp System

CSharp examples for System:DateTime Day

Description

Will give you the DateTime object given the number of days you go back.

Demo Code


using System;//from   w  ww  . j  a  v a 2  s .  c o  m

public class Main{
        /// <summary>
        /// Will give you the DateTime object given the number of days you go back.
        /// </summary>
        /// <param name="days">
        /// The days.
        /// </param>
        /// <returns>
        /// DateTime object
        /// </returns>
        public static DateTime DaysAgo(this int days)
        {
            var t = new TimeSpan(days, 0, 0, 0);
            return DateTime.Now.Subtract(t);
        }
}

Related Tutorials