Wednesday, 30 March 2016

Get all days between two dates using javascript

// Code goes here

function populate_week_range_options(){
 
    var start_week_date = new Date("2016/03/01"); // no queries exist before this
    //console.log(start_week_date);
    var todays_date = new Date("2018/03/30");

    // array to hold week commencing dates
    var week_commencing_m= new Array();
    var week_commencing_t = new Array();
   
    //week_commencing_m.push(start_week_date);

    while(start_week_date < todays_date){
        var next_date = start_week_date.setDate(start_week_date.getDate() + 1);

        start_week_date = new Date(next_date);
        //console.log(start_week_date);
      
        if(start_week_date.getDay() == 0){
         
            week_commencing_m.push(start_week_date);
        }
       if(start_week_date.getDay() == 1){
            week_commencing_t.push(start_week_date);
        }
       //
    }

    return {"m": week_commencing_m,"T":week_commencing_t};
}
console.log(populate_week_range_options());

https://plnkr.co/edit/d8n7ZeztqkJu75qSFlb0?p=preview

No comments:

Post a Comment