Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get month name instead of number

I am using the jQuery datepicker plugin. I can get the month number by

$("#datepicker").datepicker('getDate').getMonth()+1

How can I get the month name directly (i.e. without using a switch case)?

like image 341
karth Avatar asked Nov 27 '22 09:11

karth


2 Answers

If you want a simple solution this is it:

var months = [ "January", "February", "March", "April", "May", "June", 
               "July", "August", "September", "October", "November", "December" ];

var selectedMonthName = months[$("#datepicker").datepicker('getDate').getMonth()];

A more complicated but more customizable way would be to use a formatter (my comment). Then see this question and answer.

like image 168
dacwe Avatar answered Dec 05 '22 17:12

dacwe


Edit: I guess getMonthName doesn't work?

Well really the 'right' way to do this is to use formatDate: http://docs.jquery.com/UI/Datepicker/formatDate

var monthName = $.datepicker.formatDate('MM', $("#datepicker").datepicker('getDate'));
like image 21
Dave Avatar answered Dec 05 '22 17:12

Dave