I Have two date fields where I use DatePicker to pick the dates.
For the first date field, I want today's date as the default date.
For the second date field, I need today + 15
days as my default date
jQuery
$("[name=trainingStartFromDate]").datepicker({ dateFormat: 'dd-mm-yy', changeYear: true}); $("[name=trainingStartToDate]").datepicker({ dateFormat: 'dd-mm-yy', changeYear: true});
How do I set the default dates?
I have tried setDate: new Date()
for first date but it's not working.
Syntax: $(". selector"). datepicker( {defaultDate:"+6"} );
$( ". selector" ). datepicker({ defaultDate: +7 });
The jQuery UI Datepicker is a highly configurable plugin that adds datepicker functionality to your pages. You can customize the date format and language, restrict the selectable date ranges and add in buttons and other navigation options easily.
Today date:
$( ".selector" ).datepicker( "setDate", new Date()); // Or on the init $( ".selector" ).datepicker({ defaultDate: new Date() });
15 days from today:
$( ".selector" ).datepicker( "setDate", 15); // Or on the init $( ".selector" ).datepicker({ defaultDate: 15 });
jQuery ui docs
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