sam140
sam140

Reputation: 249

Assign date value (stored in variable) to date picker

Can any one suggest how to assign the date stored in variable to date picker?

I have created the function below and successfully stored a date in the format variable but I'm unable to assign the format variable value to date picker. Please suggest any idea what i am doing wrong here.

fun()
{
    format = $.datepicker.formatDate("dd-M-yy",new Date("2015-01-01"));
    alert(format)
    document.getElementById('render_SelectDate').value=format;
}

Upvotes: 0

Views: 1913

Answers (2)

Sharathi RB
Sharathi RB

Reputation: 877

Just try this one. In format you can mention your date format

$('#daydatepicker').Zebra_DatePicker({
    format: 'm-d-Y',
    direction: -1,
    onSelect: function (date) {
    ngModelCtrl.$setViewValue(date);
    scope.$apply();
    }
});

ref : http://api.jqueryui.com/datepicker/#option-dateFormat

Upvotes: 2

Adam Boduch
Adam Boduch

Reputation: 11211

I think the setDate() method is what you're looking for:

var date = new Date('2/20/2015');
$('#datepicker').datepicker('setDate', date);

Upvotes: 1

Related Questions