Get the Number of Days of Given Year.

Vishalneeraj-24503
Posted by Vishalneeraj-24503 under Visual Studio category on | Points: 40 | Views : 1473
Write below code:-
public int GetNoOfDaysInYear(int Year)
{
int NoOfDays = 0;
if (Year > 0)
{
if (DateTime.IsLeapYear(Year))
NoOfDays = 366;
else
NoOfDays = 365;
}
return NoOfDays;
}


To test above function:-
Response.Write("No of days is :- " + GetNoOfDaysInYear(DateTime.Now.Year) + "<br/>");
Response.Write("No of days is :- " + GetNoOfDaysInYear(2016) + "<br/>");
Response.Write("No of days is :- " + GetNoOfDaysInYear(2017) + "<br/>");

Output:-
No of days is :- 365
No of days is :- 366
No of days is :- 365

Comments or Responses

Login to post response