Gets the last day of month. - CSharp System

CSharp examples for System:DateTime Month

Description

Gets the last day of month.

Demo Code


using System;//  www  .j a v  a 2  s.c  o  m

public class Main{
        /// <summary>
        ///     Gets the last day of month.
        /// </summary>
        /// <param name="date">The date.</param>
        /// <returns></returns>
        public static DateTime GetLastDayOfMonth(this DateTime date)
        {
            DateTime lastDayOfMonth = new DateTime(date.Year, date.Month + 1, 1).AddDays(-1);
            return lastDayOfMonth;
        }
}

Related Tutorials