Gets the days in year.

image_pdfimage_print
   
 
using System;
public class MainClass{
        /// <summary>
        /// Gets the days in year.
        /// </summary>
        /// <param name="date">The date.</param>
        /// <returns></returns>
        public static int GetDaysInYear(DateTime date)
        {
            if (date.Equals(DateTime.MinValue))
            {
                return -1;
            }

            DateTime thisYear = new DateTime(date.Year, 1, 1);
            DateTime nextYear = new DateTime(date.Year + 1, 1, 1);

            return (nextYear - thisYear).Days;
        }
}