Is there a built-in Javascript function to turn the text string of the month into a numeric equivalent?
4 answers
Try the following:
function getMonthNumber(monthName) {
// Turn the month name into a parseable date string.
var dateString = "1 " + monthName;
// Parse the date into a numeric value (equivalent to Date.valueOf())
var dateValue = Date.parse(dateString);
// Construct a new JS date object based on the parsed value.
var actualDate = new Date(dateValue);
// Return the month. getMonth() returns 0..11, so we need to add 1
return(actualDate.getMonth() + 1);
}
+1
source to share