Skip to content

Instantly share code, notes, and snippets.

Avatar

Donnie Ashok Donnie

View GitHub Profile
@Donnie
Donnie / moment.fiscal.js
Created May 29, 2018
Best way to get the fiscal year (April-March) using moment.js
View moment.fiscal.js
if (moment().quarter() === 2) {
var thisFiscalStart = moment().month('April').startOf('month').format('YYYY-MM-DD')
var thisFiscalEnd = moment().add(1, 'year').month('March').endOf('month').format('YYYY-MM-DD')
} else {
var thisFiscalStart = moment().subtract(1, 'year').month('April').startOf('month').format('YYYY-MM-DD')
var thisFiscalEnd = moment().month('March').endOf('month').format('YYYY-MM-DD')
};
var lastFiscalStart = moment(thisFiscalStart).subtract(1, 'year').format('YYYY-MM-DD')
var lastFiscalEnd = moment(thisFiscalEnd).subtract(1, 'year').format('YYYY-MM-DD')