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!
With moment 1.7.0+ it is just
moment().startOf('quarter').format('MM-DD-YYYY');
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());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With