To Month End - CSharp System

CSharp examples for System:DateTime Month

Description

To Month End

Demo Code


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

public class Main{
        public static DateTime ToMonthEnd(this DateTime value)
        {
            DateTime monthStart = new DateTime(value.Year, value.Month, 1);
            return monthStart.AddMonths(1).AddSeconds(-1);
        }
        public static DateTime ToMonthEnd(this string value)
        {
            DateTime date = Convert.ToDateTime(value);
            DateTime monthStart = new DateTime(date.Year, date.Month, 1);
            return monthStart.AddMonths(1).AddSeconds(-1);
        }
}

Related Tutorials