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.
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.
Share Improve this question asked May 6, 2016 at 10:38 Bob the BuilderBob the Builder 5433 gold badges12 silver badges35 bronze badges4 Answers
Reset to default 13var 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.
var datestring = getDateString(new Date(opt.start);
var monthNumber = new Date(datestring).getMonth()+1;
I'm not sure this will help since I am new in this field
var today = new Date();
var month = new Array();
month[0] = "01";
month[1] = "02";
month[2] = "03";
month[3] = "04";
month[4] = "05";
month[5] = "06";
month[6] = "07";
month[7] = "08";
month[8] = "09";
month[9] = "10";
month[10] = "11";
month[11] = "12";
var monthNumber = month[today.getMonth()];
console.log("This month is " + monthNumber);
Thanks, and more simple:
var month = new Date().getMonth() + 1;
// Result, ie: January = 1 ... December = 12
var month = new Date().getMonth() + 1;
console.log("month", month);