Search code examples
javascriptdaterangepicker

Get month number from a date in javascript


I have a daterangepicker function that is returning the selected date in this format 06 May 2016. What I am trying to do is extract the month as an integer, therefore from the above I should be able to return the number 5.

This is the line of code that returns the selected date - getDateString(new Date(opt.start)

Any help is appreciated thanks.


Solution

  • var date  = new Date();
    var month = date.getMonth();
    

    The getMonth() method returns the month (from 0 to 11) for the specified date, according to local time.