Prady
Prady

Reputation: 11330

how do i assign a date to jquery ui datepicker?

I am trying to assign a date into a jquery ui datepicker. I have the date coming like Sat Jan 01 00:00:00 GMT 2011 . How can i assign this value so the datepicker.

Thanks Prady

Upvotes: 0

Views: 534

Answers (2)

Álvaro González
Álvaro González

Reputation: 146660

It looks like regular JavaScript's Date object already accepts such format, so you can perfectly do this:

var myDate = new Date("Sat Jan 01 00:00:00 GMT 2011");

Now, call datepicker.setDate() and you're done:

myDatePicker.datepicker("setDate", myDate);

Upvotes: 1

Luke Duddridge
Luke Duddridge

Reputation: 4347

The datepicker would set the date to the value in the box.

if the box is blank then the value will aways default to the value you mention.

There is a CurrentText Option but I dont know what that does.

Maybe DefaultDate would be the better option?

$(".datepicker").datepicker({ defaultDate: new Date() });

Upvotes: 1

Related Questions