I have a jquery datepicker that formats the date in dd/mm/yyyy. I need to display the month name when someone types in a date, a date is selected and on load. i’m struggling to get the month. myDate is the textbox attached to the datepicker. i have this:
var date = new Date($("#myDate").val());
alert(date.getDate());
alert(date.getMonth());
alert(date.getDay());
alert(date.getYear());
When i run it with a date of 18/07/2011, i get 5 for the month, 4 for the day, 7 for the date and 112 for the year, which is all very odd. What am i doing wrong? all i need to do is dynamically change a month label to the month selected/typed in with the datepicker i.e July…
To get date from datepicker you should use
$("#myDate").datepicker("getDate"). While what you are currently doing builds a JavaScript Date object which probably interprets the .val() in a wrong way.