When you use .endOf()
you are mutating the object it's called on, so startDate
becomes Sep 30
You should use .clone()
to make a copy of it instead of changing it
var startDate = moment(year + '-' + month + '-' + 01 + ' 00:00:00');
var endDate = startDate.clone().endOf('month');
console.log(startDate.toDate());
console.log(endDate.toDate());
Mon Sep 01 2014 00:00:00 GMT+0700 (ICT)
Tue Sep 30 2014 23:59:59 GMT+0700 (ICT)