Returns the last day of the current month. - CSharp System

CSharp examples for System:DateTime Day

Description

Returns the last day of the current month.

Demo Code


using System.Globalization;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;// w ww  .  j  av  a 2s.c om

public class Main{
        /// <summary>
        /// Returns the last day of the current month.
        /// </summary>
        /// <returns></returns>
      public static DateTime EndOfMonth()
      {
         return EndOfMonth(DateTime.UtcNow);
      }
        /// <summary>
        /// Returns the last day of the month.
        /// </summary>
        /// <param name="d"></param>
        /// <returns></returns>
      public static DateTime EndOfMonth(DateTime d)
      {
         DateTime n = new DateTime(d.Year, d.Month + 1, 1, 23, 59, 59);
         return n.AddDays(-1);
      }
}

Related Tutorials