In Moment.js, how do you get the current financial Quarter?

后端 未结 9 1709
深忆病人
深忆病人 2020-12-14 16:07

Is there a simple/built in way of figuring out the current financial quarter?

ex:

  • Jan-Mar: 1st
  • Apr-Jul: 2nd
  • Jul-Sept: 3rd
9条回答
  •  -上瘾入骨i
    2020-12-14 17:01

    START DATE

    moment().quarter(moment().quarter()).startOf('quarter');
    

    Would return the current quarter with the date set to the quarter starting date.

    moment("2019", "YYYY").quarter(4).startOf('quarter');
    

    Would return the starting date of the 4th quarter of the year "2019".

    moment().startOf('quarter');
    

    Would return the starting date of the current quarter of current year.

    END DATE

    moment().quarter(moment().quarter()).endOf('quarter');
    

    Would return the current quarter with the date set to quarter ending date.

    moment("2019", "YYYY").quarter(4).endOf('quarter');
    

    Would return the ending date of the 4th quarter of the year "2019".

    moment().endOf('quarter');
    

    Would return the ending date of the current quarter of current year.

提交回复
热议问题