Kendo DatePicker Return wrong value

Sara N picture Sara N · Aug 8, 2014 · Viewed 9.1k times · Source

I set the format of my date in this way:

$('#filterdate').kendoDatePicker({format: "dd/MM/yyyy"});

SOMEWHERE I have code which set (#filterdate)

#filterdate is 10/7/2014

but when I use this code :

$('#filterdate').data("KendoDatePicker").value();

it returns : 10 Jun 2014

why the dates are different? its really strange. I think I have problem in initializing Kendo (maybe) .

Answer

OnaBai picture OnaBai · Aug 8, 2014
  • First important question about dates is that months (as @LarsHöppner) already noted are base 0.
  • Second, depending on your language/country settings -if you are using others than defaults- you might need to use both parseFormats (used when you set a date) and format (used for displaying the date in the input box).
  • Third, there is a typo error in $('#filterdate').data("KendoDatePicker").value(); where KendoDatePicker is with lowercase K, but since you say that it shows a date instead of complaining by an undefined, it is fine.

Said so, if you initialize the DatePicker as:

var fd = $("#filterdate").kendoDatePicker({
    parseFormats:["dd/MM/yyyy"],
    format: "dd/MM/yyyy"
}).data("kendoDatePicker");

it works perfectly fine, both setting and getting a date as:

Setting:

fd.value("10/7/2014");

and Getting:

var value = fd.value();

Check it running here: http://jsfiddle.net/OnaBai/5q1tnh1j/