To Year End - CSharp System

CSharp examples for System:DateTime Year

Description

To Year End

Demo Code


using System;// w  w w . ja va 2 s  . co m

public class Main{
        public static DateTime ToYearEnd(this DateTime value)
        {
            DateTime yearStart = new DateTime(value.Year, 1, 1);
            return new DateTime(value.Year, 1, 1).AddYears(1).AddSeconds(-1);
        }
        public static DateTime ToYearEnd(this string value)
        {
            DateTime date = Convert.ToDateTime(value);
            DateTime yearStart = new DateTime(date.Year, 1, 1);
            DateTime yearEnd = new DateTime(date.Year, 1, 1).AddYears(1).AddSeconds(-1);
            return yearEnd;
        }
}

Related Tutorials