var range = getDates(new Date(), new Date().addDays(7));
I'd like "range" to be an array of date objects, one for each day between the two dates.
The trick is that it should handle month and year boundaries as well.
Thanks.
var range = getDates(new Date(), new Date().addDays(7));
I'd like "range" to be an array of date objects, one for each day between the two dates.
The trick is that it should handle month and year boundaries as well.
Thanks.
I was recently working with moment.js, following did the trick..
Result would be:
I have been using @Mohammed Safeer solution for a while and I made a few improvements. Using formated dates is a bad practice while working in your controllers.
moment().format()
should be used only for display purposes in views. Also remember thatmoment().clone()
ensures separation from input parameters, meaning that the input dates are not altered. I strongly encourage you to use moment.js when working with dates.Usage:
startDate
,endDate
parametersinterval
parameter is optional and defaults to 'days'. Use intervals suported by.add()
method (moment.js). More details heretotal
parameter is useful when specifying intervals in minutes. It defaults to 1.Invoke:
Function:
I'm using simple while loop to calculate the between dates