i have two dates like 2013-1-1 and 2013-1-10 i want to get the output like 2013-1-1,2013-1-2,2013-1-3,.....2013-1-10 how i l get this give me some solution please.
How to get the date list between two dates
Collapse
X
-
you can use the JS code
Code:Date.prototype.addDays = function(days) { var dat = new Date(this.valueOf()) dat.setDate(dat.getDate() + days); return dat; } function getDates(startDate, stopDate) { var dateArray = new Array(); var currentDate = startDate; while (currentDate <= stopDate) { dateArray.push( new Date (currentDate) ) currentDate = currentDate.addDays(1); } return dateArray; }Comment
-
The date subtraction answer is returned in milliseconds.
Divide it by 86400000 to get the number of days.
Code:var from = '2020-10-01'; var to = '2020-10-10' var from_day = new Date(from); var to_day = new Date(to); var term = (to_day - from_day) / 86400000; var date_arry = [from]; for (var i = 0; i < term; i++) { var dt = new Date(from_day.setDate(from_day.getDate() + 1)); str = dt.getFullYear() + '-' + ('0' + (dt.getMonth() + 1)).slice(-2) + '-' + ('0' + dt.getDate()).slice(-2); date_arry.push(str); }Comment
Comment