Bob the Builder Bob the Builder - 2 years ago 121
Javascript Question

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.

Answer Source
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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download