OyvindLE
6/26/2014 - 7:32 AM

Hent datoer mellom to datoer

Hent datoer mellom to datoer

var startDate = new Date("2014-06-01"),
    endDate = new Date("2014-07-01")

function getAllDays(s, e) {
    var a = [];

    while(s < e) {
        a.push(formatDate(s));
        s = new Date(s.setDate(
            s.getDate() + 1
        ))
    }

    return a;
}

function formatDate(d) {
    var curr_date = d.getDate();
    var curr_month = d.getMonth() + 1; //Months are zero based
    var curr_year = d.getFullYear();
    return  curr_date + "-" + curr_month + "-" + curr_year;
}

alert(getAllDays(startDate, endDate).join("\n"));