I'm attempting to create an array of dates in Javascript based on a start date and an end date. I need the date format to look like 2013-04-25
My code apparently doesn't work, but I can't seem to figure out why. Can someone assist?
//get today's date
var today = new Date();
today.setDate(today.getDate());
//get date from last week -7
var prevWeek = new Date();
prevWeek.setDate(prevWeek.getDate() -7);
//set initial date parameters
var fromDate = prevWeek;
var toDate = today;
//set date parameters to input parameters
function setDates() {
fromDate =document.getElementById('fromDate').value;
toDate = document.getElementById('toDate').value;
};
var dates = new Array();
//create date array
function setArray() {
for(i = fromDate.getDate(), i <= toDate.getDate(), i.setDate(i.getDate() +1))
{
dates.push(new Date(i));
};
};
//format date array
function formDates() {
for(i = 0, i <= dates.length, i++)
{
var dd = dates[i].getDate();
var mm = dates[i].getMonth()+1;
var yyyy = dates[i].getFullYear();
if(dd<10) {dd = '0' + dd};
if(mm<10){mm = '0' + mm};
dates[i] = yyyy + '-' + mm + '-' + dd;
};
};