Click here to Skip to main content
16,012,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to get month name from dateparameter

var d = new Date($("#txtInvMgmtToDate").val());

var monthname = monthNames[d.getMonth()]

What I have tried:

var d = new Date($("#txtInvMgmtToDate").val());

var monthname = monthNames[d.getMonth()]
Posted
Updated 7-Mar-16 17:47pm
Comments
[no name] 7-Mar-16 23:43pm    
Are you using jQuery date picker? Secondly what is the value you are getting at "$("#txtInvMgmtToDate").val()"?
Member 12369428 7-Mar-16 23:49pm    
here I am selecting date from datepicker and stored into "txtInvMgmtToDate" this textbox

1 solution

Try with below code:
JavaScript
// Declaring all month names in an array
var month = [];
month[0] = "January";
month[1] = "February";
month[2] = "March";
month[3] = "April";
month[4] = "May";
month[5] = "June";
month[6] = "July";
month[7] = "August";
month[8] = "September";
month[9] = "October";
month[10] = "November";
month[11] = "December";

// Convert string value to date object
var d = new Date($("#txtInvMgmtToDate").val());

// Get the month number from date object and assign it to array for monthName
var monthName = month[d.getMonth()];
alert(monthName);
 
Share this answer
 
v2
Comments
Animesh Datta 8-Mar-16 0:14am    
My 5!
[no name] 8-Mar-16 0:41am    
:)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900