Last week I needed to work with the UK Standard Financial Year, based on a date being passed into a function to narrow a query down.
The following code takes in a DateTime parameter and returns the Pair() structure with the StartDate of the FY and the EndDate of the FY.
public static Pair GetFinancialYear(DateTime pDate)
{
Pair FinancialYear = new Pair();
//If the passed in month is less than 4 then we need to calculate the FYStart based on the previous Year.
if (pDate.Month < 4)
{
FinancialYear.First = new DateTime(pDate.Year - 1, 4, 1);
FinancialYear.Second = new DateTime(pDate.Year, 3, 31);
}
//Else the FYStart stays the same but the FYEnd is next year.
else
{
FinancialYear.First = new DateTime(pDate.Year, 4, 1);
FinancialYear.Second = new DateTime(pDate.Year + 1, 3, 31);
}
return FinancialYear;
}
Do you know a better way of doing this?