41
votes

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.

6
Could 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
He 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
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
I use the jQuery-UI datepicker - MACMAN
@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

6 Answers

58
votes

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')

53
votes

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 :)

19
votes

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() });
11
votes

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"); 
8
votes

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

0
votes

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

and return empty string from backend