Angular 2+ Get Current Financial Year/Fiscal Year

0
1329

     Here is the code how you get current financial year :-

 
    var date = new Date();
    if(moment(date).format('MMMM') > 'March')
    {
      this.financialYear = parseInt(moment(date).format("YYYY"))+'-'+parseInt(moment(date).add(1, 'years').format("YYYY"));
    }
    else{
      this.financialYear = parseInt(moment(date).subtract(1,'years').format("YYYY"))+'-'+parseInt(moment(date).format("YYYY"));
    }
  

And if you have to GO TO PREVIOUS or GO TO NEXT year here is the code for that too :-

year:any=[];
yearFinancial(action:any)
{
  console.log(this.financialYear);
  this.year = this.financialYear.split('-');
  console.log(this.year);
  if(action == 'next')
  {
    var initialYear = parseInt(this.year[0]) + 1;
    var finalYear = parseInt(this.year[1]) + 1;
  }
  else if(action == 'prev'){
    var initialYear = parseInt(this.year[0]) - 1;
    var finalYear = parseInt(this.year[1]) - 1;
  }
  this.financialYear = initialYear+'-'+finalYear;
  console.log(this.financialYear);
  this.getPreventiveList(this.pageSize,this.currentPage,'');
}

LEAVE A REPLY

Please enter your comment!
Please enter your name here