i am trying to convert a string in the format dd-mm-yyyy into a date object in JavaScript using the following:
var from = $(\"#datepicker\").val(); var to
You could use a Regexp.
var result = /^(\d{2})-(\d{2})-(\d{4})$/.exec($("#datepicker").val()); if (result) { from = new Date( parseInt(result[3], 10), parseInt(result[2], 10) - 1, parseInt(result[1], 10) ); }