In my situation, I have to set the month to last month as default.
The default month for the datepicker is current month. But I want it to be last month or other month as default showing. How can I make it?
Such as: "2010-09" as the default.
Thank you very much!
You can use the defaultDate
option when creating the datepicker:
$('#date').datepicker({
defaultDate: '-2m'
});
By passing in a string like this we can set the default date to another one relative to the current date. Alternatively, the option also accepts a Date
object:
defaultDate: new Date(2010, 8, 1)
or a string in the same format as the format currently defined:
defaultDate: '1/9/2010'
All of the above will give you a default date in September. The month in the Date
constructor starts from zero, so 8 will give you September.
I think you actually want this when you're only showing 1 month at a time.
$( ".selector" ).datepicker({ showCurrentAtPos: 1 });
If you use defaultDate it will highlight that particular day, this method just shows the previous month with nothing selected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With