Reputation: 119
I am using Kendodatepicker.below is my code.
<input id="datePicker" />
$(document).ready(function(){
$("#datePicker").kendoDatePicker({
value: new Date(),
min: new Date(1950, 0, 1),
max: new Date(2049, 11, 31)
})
});
I want to put the datepicker default selected value as last month start date .please give me an idea. Thanks in advance
Upvotes: 0
Views: 14308
Reputation: 164
First get current date using Date() and then subtract a month and then set it to the first of the month.
$(document).ready(function() {
var lastMonthStart = new Date(); with(lastMonthStart) { setMonth(getMonth()-1); setDate(1); } $("#datePicker").kendoDatePicker({ value: lastMonthStart, min: new Date(1950, 0, 1), max: new Date(2049, 11, 31) }) });
Should give you the start of last month.
Upvotes: 1
Reputation: 1525
try
$(document).ready(function(){
var d = new Date().setDate(-1);
$("#datePicker").kendoDatePicker({
value: new Date(d),
min: new Date(1950, 0, 1),
max: new Date(2049, 11, 31)
})
});
or
$(document).ready(function(){
var d = new Date().setDate(-1);
$("#datePicker").attr('value',new Date(d));
$("#datepicker").kendoDatePicker();
});
probably it works in super short way:
$(document).ready(function(){
$("#datePicker").kendoDatePicker({
value: new Date().setDate(-1),
min: new Date(1950, 0, 1),
max: new Date(2049, 11, 31)
})
});
have fun
Upvotes: 2