How to get current and previous financial year datewise in ruby based on current date ?
current_month = Time.current.month
current_year = current_month > 3 ? Time.current.year :Time.current.year - 1
start_date = '/04/01'
end_date = '/03/31'
current_financial_year = [current_year.to_s + start_date , (current_year + 1).to_s + end_date]
previous_financial_year = [(current_year-1).to_s + start_date, current_year.to_s + end_date]
Financial years are defined differently in different countries (see: Wikipedia). In your country, the following might work. Keep in mind that you need to adjust the calculation when you want to support multiple jurisdictions.
Note that my methods return ranges instead of arrays which define the financial period.