Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

asp.net

I would like to get the total number of days in a year left from the given date .. Assume if a user gives 04-01-2011(MM-DD-YYYY) I would like to find the remaining days left. How to do this..

like image 578
Vivekh Avatar asked May 08 '12 09:05

Vivekh


People also ask

How do you calculate the number of days from a date?

To calculate the number of days between two dates, you need to subtract the start date from the end date.

How do I extract the number of days from a date in Excel?

To find the number of days between these two dates, you can enter “=B2-B1” (without the quotes into cell B3). Once you hit enter, Excel will automatically calculate the number of days between the two dates entered.

How do you calculate 365 days in a year?

So to correct (approximately), we add 1 day every four years (leap year). Thus, three calendar years are 365 days long; the fourth calendar year is 366 days long. The average length of the calendar year in days now becomes: (3 x 365 + 366)/4 = 365.25 days.


2 Answers

Perhaps just:

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

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

like image 177
Peter Avatar answered Oct 12 '22 22:10

Peter


should do the trick

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

like image 34
ry8806 Avatar answered Oct 12 '22 22:10

ry8806