Returns the FIRST possible time unit for provided MONTH in dateTime - CSharp System

CSharp examples for System:DateTime Month

Description

Returns the FIRST possible time unit for provided MONTH in dateTime

Demo Code


using System.Globalization;
using System;/* w w  w  . ja v a  2 s  .  c  om*/

public class Main{
        /// <summary>
        /// Returns the FIRST possible time unit for provided MONTH in dateTime
        /// </summary>
        public static DateTime StartOfMonth(this DateTime dateTime)
        {
            DateTime startOfMonth = dateTime.AddDays(-dateTime.Day + 1).Date;

            return startOfMonth;
        }
}

Related Tutorials