Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery DatePicker Set default date

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.

like image 649
maaz Avatar asked Jan 29 '13 10:01

maaz


People also ask

How do I set the default date in datepicker?

Syntax: $(". selector"). datepicker( {defaultDate:"+6"} );

How do I change the default month in datepicker?

$( ". selector" ). datepicker({ defaultDate: +7 });

What is datepicker in jQuery?

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.


1 Answers

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

like image 99
gdoron is supporting Monica Avatar answered Sep 18 '22 15:09

gdoron is supporting Monica