Gets the Financial year For the given date.

Vishalneeraj-24503
Posted by Vishalneeraj-24503 under Visual Studio category on | Points: 40 | Views : 233
Write below code:-
public int GetFinancialYear(DateTime GivenDate)
{
int FinancialYear = 0;
if (GivenDate > DateTime.MinValue)
{
if (GivenDate.Month > 3)
{
FinancialYear = GivenDate.Year + 1;
}
else
{
FinancialYear = GivenDate.Year;
}
}

return FinancialYear;
}

Now,to check above function:-
Response.Write("Financial Year for March 2015 is:- " + GetFinancialYear(DateTime.Now) + "<br/>");
Response.Write("Financial Year for May 2015 is:- " + GetFinancialYear(DateTime.Now.AddMonths(2)) + "<br/>");


Output:-
Financial Year for March 2015 is:- 2015
Financial Year for May 2015 is:- 2016

Comments or Responses

Login to post response