How to get the quarter from a date in TypeScript

1 Answer

0 votes
function getQuarterFromADate(date = new Date()) {
  	return Math.floor(date.getMonth() / 3 + 1);
}

console.log(getQuarterFromADate(new Date('2023-02-11'))); 

  
  
  
  
/*
run:
  
1
  
*/

 



answered Apr 11, 2022 by avibootz
...