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

CSharp examples for System:DateTime Hour

Description

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

Demo Code


using System;/* w w w  .java2 s .  c o  m*/

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

Related Tutorials