How to get the total number of days in a year from the given date

should do the trick

int daysLeft = new DateTime(DateTime.Now.Year, 12, 31).DayOfYear - DateTime.Now.DayOfYear;


Perhaps just:

DateTime.IsLeapYear(DateTime.Now.Year) ? 366 : 365

Sorry, read it as if you just wanted the number of days in current year...


Let's say the date is today:

var user = "05-08-2012";
var date = DateTime.ParseExact(user, "MM-dd-yyyy", System.Globalization.CultureInfo.InvariantCulture);
var lastdate = new DateTime(date.Year, 12, 31);
var diff = lastdate - date;

diff.TotalDays contains the number of days (thanks @Tung). lastdate also contains the last date for the year.

Tags:

C#

Asp.Net