Finding the number of months encompassed between the given dates.

Vishalneeraj-24503
Posted by Vishalneeraj-24503 under Sql Server category on | Points: 40 | Views : 226
Below code snippets is written for Finding the number of months encompassed between the given dates:-
public int GetNoOfMonthsEncompassedByDates(DateTime StartDate, DateTime EndDate)
{
return Math.Abs(12 * (StartDate.Year - EndDate.Year) + StartDate.Month - EndDate.Month) + 1;
}


int result = GetNoOfMonthsEncompassedByDates(DateTime.Now, DateTime.Now.AddMonths(7));
Response.Write(result + "<br/>");

Output:- 8

Comments or Responses

Login to post response