Returns the LAST possible time unit for provided DAY in dateTime - CSharp System

CSharp examples for System:DateTime Day

Description

Returns the LAST possible time unit for provided DAY in dateTime

Demo Code


using System.Globalization;
using System;/*from   ww w  . jav a  2  s.  c  o  m*/

public class Main{
        #endregion

        #region End of Day/Week/Month/Year

        /// <summary>
        /// Returns the LAST possible time unit for provided DAY in dateTime
        /// </summary>
        public static DateTime EndOfDay(this DateTime dateTime)
        {
            return dateTime.Tomorrow().AddTicks(-1);
        }
        #region Tomorrow & Yesterday

        /// <summary>
        /// Get start time of tomorrows day
        /// </summary>
        public static DateTime Tomorrow(this DateTime dateTime)
        {
            return dateTime.AddDays(1).StartOfDay();
        }
}

Related Tutorials