Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

64
Views
how do I get previous 3 or 5 financial years dynamically.eg 2021-20, 2020-19
`function getCurrentFinancialYear()
 {
  const thisYear = (new Date()).getFullYear();
  const lastYear = thisYear-1;
  return ${lastYear}-${thisYear.toString().slice(-2)};
}
console.log(getCurrentFinancialYear());` 

This is giving the output only 2020-21

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You should run the year calculation logic in a loop.

I have used Array.map to generate the 5 years and used Array.join to convert the Array s=as a string.

Working Fiddle

function getCurrentFinancialYear() {
  const thisYear = (new Date()).getFullYear();
  const yearArray = [0, 1, 2, 3, 4].map((count) => `${thisYear - count}-${(thisYear - count - 1).toString().slice(-2)}`);
  console.log(yearArray);
  return yearArray.join();
}
console.log(getCurrentFinancialYear());

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!