I am using a Jquery Datepicker in my project. The problem is that it is not loading the current date, but showing a date 1st January 2001 as default. Can you please let me know how the default date can be corrected so it will display the current date.
-
7Could you please provide some code to work with, if we cannot see what YOU are doing wrong, there is no way WE can help YOU! – DonSeba Jul 11 '11 at 6:13
-
1He makes a point, we're all making up JQuery syntax from scratch. If you include your code, we could come up with more relevant answers. – ghayes Jul 11 '11 at 6:18
-
What datepicker? one of the numerous datepickers such as this one or the jQuery-UI datepicker? Note that jQuery-UI datepicker defaults to today so make sure your system date/time is correct. – Salman A Jul 11 '11 at 6:27
-
I use the jQuery-UI datepicker – MACMAN Jul 11 '11 at 6:41
-
@Gijo: by default the datepicker will default to the date present in the attached control or current date; unless your code tells to behave otherwise. Can you edit your question and post the code? – Salman A Jul 11 '11 at 6:53
interesting, datepicker default date is current date as I found,
but you can set date by
$("#yourinput").datepicker( "setDate" , "7/11/2011" );
don't forget to check you system date :)
-
2This may be the accepted answer, but it is the right one. The question was setting a default, which is different from an unconditional set. – James A Mohler Jul 28 '13 at 23:37
Use the defaultDate option
$( ".selector" ).datepicker({ defaultDate: '01/01/01' });
If you change your date format, make sure to change the input into defaultDate (e.g. '01-01-2001')
Are u using this datepicker http://jqueryui.com/demos/datepicker/ ? if yes there are options to set the default Date.If you didn't change anything , by default it will show the current date.
any way this will gives current date
$( ".selector" ).datepicker({ defaultDate: new Date() });
-
1This did not work in my case:
$(".datepicker").datepicker({ dateFormat: 'dd.mm.yy', defaultDate: new Date() });
, I had to add an additional line with$(".datepicker").datepicker("setDate", "-0d");
– basZero Jan 16 '18 at 7:54
While the defaultDate does not set the widget. What is needed is something like:
$(".datepicker").datepicker({
showButtonPanel: true,
numberOfMonths: 2
});
$(".datepicker[value='']").datepicker("setDate", "-0d");
i suspect that your default date format is different than the scripts default settigns. test your script with the 'dateformat' option
$( "#datepicker" ).datepicker({
dateFormat: 'dd-mm-yy'
});
instead of dd-mm-yy, your desired format
$( ".selector" ).datepicker({ defaultDate: null });
and return empty string from backend