I need a financial year based on current or today's datetime.
Suppose if we consider today's date is 10 April 2011
, then i need the outputs as Financial Year 2012
and for some cases i need to display the same output in short format as FY12
. Both ways i want to display.
In our requirement financial Year considered is from April
(the current year) to March
(following year).
Based on current datetime...the scenario of output is depends on the current datetime falls in the below said period or duration.
From 01April2011 to 31March2012 - Financial Year 2012 or FY2012
From 01April2012 to 31March2013 - Financial Year 2013 or FY2013
From 01April2013 to 31March2014 - Financial Year 2014 or FY2014
.
.
.
so on....
Another example: If we take today's datetime as 16April2012, then the output is needed as Financial Year 2013
and also FY13
.
Please help how to acheive the same in very short format using LINQ or Regex in C#, .Net3.5
For instance, if your financial year is from 1 April 2020 to 31 March 2021, then it is known as FY 2020-21. The assessment year for the money earned during this period would begin after the financial year ends – that is from 1 April 2021 to 31 March 2022. Hence, the assessment year would be AY 2022-22.
A couple of Extension methods
public static class DateTimeExtensions
{
public static string ToFinancialYear(this DateTime dateTime)
{
return "Financial Year " + (dateTime.Month >= 4 ? dateTime.Year + 1 : dateTime.Year);
}
public static string ToFinancialYearShort(this DateTime dateTime)
{
return "FY" + (dateTime.Month >= 4 ? dateTime.AddYears(1).ToString("yy") : dateTime.ToString("yy"));
}
}
I've done the before by creating a FinancialYear
class:
public class FinancialYear
{
int yearNumber;
private static readonly int firstMonthInYear = 4;
public static FinancialYear Current
{
get { return new FinancialYear(DateTime.Today); }
}
public FinancialYear(DateTime forDate)
{
if (forDate.Month < firstMonthInYear) {
yearNumber = forDate.Year + 1;
}
else {
yearNumber = forDate.Year;
}
}
public override string ToString() {
return yearNumber.ToString();
}
}
Other points:
Where the financial year is variable (e.g. a company financial year may run July > June rather than follow April > March tax year)
/// <summary>
/// Extension method to get the start of the financial year
/// </summary>
public static DateTime GetStartOfFinancialYear(this DateTime date, int startMonthOfFinancialYear)
{
if (startMonthOfFinancialYear < 1 || startMonthOfFinancialYear > 12)
throw new ArgumentException("Must be between 1 and 12","startMonthOfFinancialYear");
DateTime rtn = new DateTime(date.Year,startMonthOfFinancialYear,1);
if (date.Month < startMonthOfFinancialYear)
{
// Current FY starts last year - e.g. given April to March FY then 1st Feb 2013 FY starts 1st April 20*12*
rtn = rtn.AddYears(-1);
}
return rtn;
}
// Example, Financial Year starts in July
DateTime startFY = DateTime.Now.GetStartOfFinancialYear(7);
DateTime endFY = startFY.AddYears(1).AddDays(-1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With