Resets the time part to 00:00:00. - CSharp System

CSharp examples for System:DateTime Time

Description

Resets the time part to 00:00:00.

Demo Code

//     Copyright (c) Rico Suter. All rights reserved.
using System;/* w  ww  .j  a  va2  s  . c  o  m*/

public class Main{
        /// <summary>Resets the time part to 00:00:00. </summary>
        /// <param name="dt">The date time to work with. </param>
        /// <returns>The new date time. </returns>
        public static DateTime? ToStartOfDay(this DateTime? dt)
        {
            return dt.HasValue ? dt.Value.ToStartOfDay() : (DateTime?)null;
        }
        /// <summary>Resets the time part to 00:00:00. </summary>
        /// <param name="dt">The date time to work with. </param>
        /// <returns>The new date time. </returns>
        public static DateTime ToStartOfDay(this DateTime dt)
        {
            return new DateTime(dt.Year, dt.Month, dt.Day, 0, 0, 0);
        }
}

Related Tutorials