month javascript get data range code example

Example: month javascript get data range

$(function(){
var formatted_date = function(date){
                var m = ("0"+ (date.getMonth()+1)).slice(-2); // in javascript month start from 0.
                var d = ("0"+ date.getDate()).slice(-2); // add leading zero 
                var y = date.getFullYear();
                return  m +'-'+d+'-'+y; 
}
         var curr_date =new Date();
     
         var first_day = new Date(curr_date.getFullYear(), curr_date.getMonth(), 1); 
 
         var last_day = new Date(curr_date.getFullYear(), curr_date.getMonth() + 1, 0);
                 
         var month_start_date =formatted_date(first_day);
                 
         var month_end_date =formatted_date(last_day);
                 
         date=month_start_date + ' To '+month_end_date; // date range for current month
 
        /*
         var month_end_date =formatted_date(new Date()); // limit current month date range upto current day.
       */
 
 
});

Tags:

Misc Example