1

I'm getting the data from the jquery datepicker plugin. This is the exact date that I'm getting: Thu Apr 02 2015. How do I format it into this: 20150402 ??

I've tried some things but nothing is working so far. This is my code so far:

$("#button").click(function(){

                var datum = $("#datepicker").datepicker("getDate");
                console.log(datum);



            });
Max
  • 45
  • 3
  • 10

2 Answers2

1

getDate returns a date object, so you can just extract from that

$("#button").click(function(){
    var datum     = $("#datepicker").datepicker("getDate");
    var formatted = $.datepicker.formatDate('yymmdd', datum);
});

FIDDLE

Changing the date format in the datepicker settings would change the format of the value passed, but not the format of the date object retrieved with getDate.

adeneo
  • 312,895
  • 29
  • 395
  • 388
1

Hi you can check the follows:

var datum = $("#datepicker").datepicker({ dateFormat: 'yyyymmdd' }).val();
console.log(datum);
Bashar Abutarieh
  • 854
  • 1
  • 8
  • 18