chriz
chriz

Reputation: 1345

set today date with respective format that initialized earlier on jquery datepicker

I have already initialized my jquery datepicker with the format dd-M-yyyy. On some particular event I want to set that datepicket with today's date with the respective date format(dd-M-yyyy) that already I have set. I tried these codes but none of them are working, help me..

html

  <input id="SD_WO_DATE" readonly="readonly" type="text">

js

 $("#SD_WO_DATE").datepicker().datepicker( "option", "defaultDate", new Date() );

and

$("#SD_WO_DATE").datepicker().datepicker("setDate", new Date());

These are setting date with mm-dd-yyyy which I don't want.

Upvotes: 1

Views: 142

Answers (1)

Shaunak D
Shaunak D

Reputation: 20646

Demo

Use setDate property of datepicker with today as the value,

$('#SD_WO_DATE').datepicker({ dateFormat: 'dd-M-yy' });

$('button').click(function(){
    $('#SD_WO_DATE').datepicker('setDate', 'today');
});

Upvotes: 1

Related Questions