CSharp examples for System:DateTime Year
Returns the LAST possible time unit for provided YEAR in dateTime
using System.Globalization; using System;//ww w. ja v a 2s. c o m public class Main{ /// <summary> /// Returns the LAST possible time unit for provided YEAR in dateTime /// </summary> public static DateTime EndOfYear(this DateTime dateTime) { return dateTime.StartOfYear().AddYears(1).AddTicks(-1); } /// <summary> /// Returns the FIRST possible time unit for provided YEAR in dateTime /// </summary> public static DateTime StartOfYear(this DateTime dateTime) { var startOfYear = new DateTime(dateTime.Year, 1, 1); return startOfYear; } }