Reputation: 129
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>
Upvotes: 2
Views: 5839
Reputation: 807
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.
Upvotes: 0