Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find the current financial Quarter first date using moment.js

I have read many posts here but couldn't get what I wanted. I am currently new to Javascript and don't know how to get the first Date of the current quarter in MM-DD-YYYY format.

Thanks in advance!

like image 784
Alok Avatar asked Sep 23 '14 12:09

Alok


2 Answers

With moment 1.7.0+ it is just

moment().startOf('quarter').format('MM-DD-YYYY');
like image 159
Kris Dahl Avatar answered Oct 05 '22 11:10

Kris Dahl


Getting the date in JavaScript, using moment.js to format:

var qtrDate = (function () {
    var d = new Date(),
        m = d.getMonth() - d.getMonth() % 3;
    return moment(new Date(d.getFullYear(), m, 1)).format('MM-DD-YYYY');
}());

or

function getQuarterFirstDay (d) {
    var m = d.getMonth() - d.getMonth() % 3;
    return moment(new Date(d.getFullYear(), m, 1)).format('MM-DD-YYYY');
}
var d = getQuarterFirstDay(new Date());
like image 27
user4040648 Avatar answered Oct 05 '22 11:10

user4040648