2

I am working on kendo ui DatePicker,I want to set min date to yesterday.

Could anyone help me?

I have tried this

 var minDate = date.setDate((new Date()).getDate() - 1);

but of no use.

here is my code.

<body>
<div id="example" ng-app="KendoDemos">
    <div class="demo-section k-content"ng-controller="MyCtrl">
        <div class="box-col">
            <h4>Select date:</h4>
            <input kendo-date-picker
             ng-model="dateString"
             k-options="monthSelectorOptions"
             k-ng-model="dateObject"

             />

    </div>
    <style>
        .box-col {
            width: 400px;
        }
    </style>
</div>

<script>
  angular.module("KendoDemos", [ "kendo.directives" ])
      .controller("MyCtrl", function($scope){
    var date = new Date();

        $scope.monthSelectorOptions = {
             min: date
          };

      })
</script>
Neha Shukla
  • 3,572
  • 5
  • 38
  • 69
Vasu
  • 129
  • 2
  • 9

2 Answers2

4

Its pretty easy to do so. Here is an example:

http://dojo.telerik.com/ArEMa

knikolov
  • 1,650
  • 1
  • 12
  • 18
0

Fairly simple:

var date = new Date();
var yesterday = date.getDay() -1;
var minDate = date.setDate(yesterday);
$scope.monthSelectorOptions = {
      min: new Date(minDate)
 };

Edit: Apparently, the new Date(minDate) is the crutial part, because date.setDate() does not give you a UTC-formatted date-string, but new Date() does. Kendo Datepicker only takes UTC-formatted dates as parameter.

Florian-Rh
  • 777
  • 8
  • 26