Returns a datetime for the DateTime passed to it, but with zeroed time information. - CSharp System

CSharp examples for System:DateTime Format

Description

Returns a datetime for the DateTime passed to it, but with zeroed time information.

Demo Code


using System.Globalization;
using System.Windows.Forms;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/* w  w w .j  a va2 s . com*/

public class Main{
        // ---------------------------------------------------------------------------------------
        // ThisHour
        // Returns a datetime for the DateTime passed to it, but with zeroed time information.
        //// ---------------------------------------------------------------------------------------
        public static DateTime ThisHour(DateTime oDateTime)
        {
            DateTime oNewDateTime = new DateTime(
                    oDateTime.Year,
                    oDateTime.Month,
                    oDateTime.Day,
                    oDateTime.Hour,
                    0,
                    0
                    );

            return oNewDateTime;
        }
}

Related Tutorials