Wednesday, June 5, 2024
 Popular · Latest · Hot · Upcoming
72
rated 0 times [  73] [ 1]  / answers: 1 / hits: 32340  / 9 Years ago, mon, april 6, 2015, 12:00:00

I've two dates



2015-3-30      2013-8-31


How can I make a month list like:



[ '2015-3', '2015-2', '2015-1', '2014-12', '2014-11', '2014-10', '2014-09', '2014-08', '2014-07', '2014-06', '2014-05'....., '2013-08' ] 


Thanks.


More From » momentjs

 Answers
28

This should do it:


var startDate = moment('2021-12-31');
var endDate = moment('2022-12-14');
var betweenMonths = [];

if (startDate < endDate){
var date = startDate.startOf('month');

while (date < endDate.endOf('month')) {
betweenMonths.push(date.format('YYYY-MM'));
date.add(1,'month');
}
}

[#67189] Thursday, April 2, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
elaine

Total Points: 628
Total Questions: 111
Total Answers: 104

Location: Marshall Islands
Member since Tue, Sep 21, 2021
3 Years ago
;