Answers for "js date get month return 0"

11

javascript get current month start and end date

var date = new Date();
var firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
var lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0);
Posted by: Guest on May-02-2020
0

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.
       */
 
 
});
    
Posted by: Guest on May-28-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language