0

I am using datepicker to select dates from a calendar and it all works fine. However, the dates are given in numbered format when I alert them: Eg: 5-4-2017

How can I get the month in wording instead? Eg: 5-Apr-2017

The jquery looks like this:

$("#txtTo").datepicker({
    numberOfMonths: 1,
    onSelect: function(selected) {
      txtToDate = selected;
      var dt = new Date(selected);
      dt.setDate(dt.getDate() - 1);
      $("#txtFrom").datepicker("option", "maxDate", dt);
    }
});

and I used this to get the dates:

var date1 = $("#txtFrom").datepicker('getDate'),
day_1  = date1.getDate(),  
month_1 = date1.getMonth() + 1,              
year_1 =  date1.getFullYear();

How can I get the month in a different format?

Hope you can help and here is my pen if needed

Ragmah
  • 413
  • 3
  • 12
  • 1
    Check out this earlier post from the stack http://stackoverflow.com/questions/20946475/how-to-change-date-format-using-jquery – IceCode Apr 07 '17 at 08:15
  • 1
    The `date1` is stored as a date object - when you 'alert' it the browser formats it for you how it feels appropriate. When you use get_Month() you're getting the month index (0 based). Browsers are non-language specific (work in all languages) so won't ouput "Apr" as that's language specific. You can use an array or a 3rd party library. – freedomn-m Apr 07 '17 at 08:16
  • 1
    Answers very useful and It seems to work. Appreciate the support – Ragmah Apr 07 '17 at 08:22
  • 1
    pls see http://codepen.io/anon/pen/mWZbQB?editors=1111 – selvarajmas Apr 07 '17 at 08:43

0 Answers0