admin管理员组

文章数量:1431420

I have got problem with setting date to kendo ui date picker, I am successfully able to set the today date by using the following code :

  var todayDate = new Date();
  $('#createdonend').data("kendoDatePicker").value(todayDate);

I am not able to set the yesterday date by using following code

 var todayDate = new Date();
 var yesterdayDate = todayDate.getDate() - 1;
  $('#createdonbegin').data("kendoDatePicker").value(yesterdayDate);

for the above function I am getting error like this

Microsoft JScript runtime error: Object doesn't support this property or method in this file /Scripts/kendo/2013.2.716/kendo.all.min.js

would any one pls help on this one why i am getting this error for setting yesterday date to kendo ui datepicker..

Many thanks In advance..

I have got problem with setting date to kendo ui date picker, I am successfully able to set the today date by using the following code :

  var todayDate = new Date();
  $('#createdonend').data("kendoDatePicker").value(todayDate);

I am not able to set the yesterday date by using following code

 var todayDate = new Date();
 var yesterdayDate = todayDate.getDate() - 1;
  $('#createdonbegin').data("kendoDatePicker").value(yesterdayDate);

for the above function I am getting error like this

Microsoft JScript runtime error: Object doesn't support this property or method in this file /Scripts/kendo/2013.2.716/kendo.all.min.js

would any one pls help on this one why i am getting this error for setting yesterday date to kendo ui datepicker..

Many thanks In advance..

Share Improve this question asked Sep 23, 2013 at 14:48 Glory RajGlory Raj 17.7k27 gold badges111 silver badges214 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

As @Niels said you have to use:

yesterdayDate.setDate(today.getDate() - 1);

for setting yesterday date but you need to have yesterdayDate initialized to today's Date before setting it to previous day since setDate only sets the day of the month.

So, the proposed code is:

// Create a "date" object with today's date
var date = new Date();
// Changes the day of the month to previous, this keeps in mind month and year changes
date.setDate(date.getDate() - 1);
// Set the new date
$('#createdonbegin').data("kendoDatePicker").value(date);

Running example in JSFiddle: http://jsfiddle/OnaBai/v7UPr/

You will need to use the following:

yesterdayDate.setDate(today.getDate() - 1);

getDate will get the number of days in the month, not a Date object.

The value returned by getDate is an integer between 1 and 31.

Sources:

  1. getDate

本文标签: javascriptnot able to set the yesterday date to kendo ui datepickerStack Overflow