Get dates for last quarter and this quarter through Javascript
Simple generic solution in pure JS.
First calculate quarter number:
const quarter = Math.floor((today.getMonth() / 3));
const today = new Date();
Next, current quarter:
const startFullQuarter = new Date(today.getFullYear(), quarter * 3, 1);
const endFullQuarter = new Date(startFullQuarter.getFullYear(), startFullQuarter.getMonth() + 3, 0);
Previous quarter
const startFullQuarter = new Date(today.getFullYear(), quarter * 3 - 3, 1);
const endFullQuarter = new Date(startFullQuarter.getFullYear(), startFullQuarter.getMonth() + 3, 0);
Add or subtract 3's
per quarter in expression new Date(today.getFullYear(), quarter * 3 - x, 1)
to get future or past quarters.
if you're using moment.js this might be easier:
var quarterAdjustment= (moment().month() % 3) + 1;
var lastQuarterEndDate = moment().subtract({ months: quarterAdjustment }).endOf('month');
var lastQuarterStartDate = lastQuarterEndDate.clone().subtract({ months: 3 }).startOf('month');
conversion to date.js should be fairly easy.