javascriptcalendardaterangepickerangular-daterangepicker

How to get check for current month in Daterangepicker?


I want to do something like this, I tried multiple ways but I am unable to find it. I am getting start and end date but not the current month. I want current month so it works with all locale

if(CURRENT MONTH){
  // Do This
}

Solution

  • use the Date object for get month as follows,

    var date = new Date(); // assume date is 10/06/2020
    var month = date.getMonth(); // it return month as 10
    

    if you want to get month name, firstly you should declare the array including with months and then get the month name using this array as follows,

    var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
    var date = new Date(); // assume date is 10/06/2020
    var nameOfMonth = months[date.getMonth()-1] // it return month name as October
    

    then you can use month or nameOfMonth as follows,

    if (month == 10){
        // Do This
    }
    
    if (nameOfMonth == 'October'){
        // Do This
    }