Question

I have a date string "17/02/2013" that I would like to convert to a js date object formatted @dd-mm-yy but don't know how. Any suggestions? and i need to set this date as minDate in datepicker

My JQuery Code :

   var time_value = result.sdate;
   var values = time_value.split("/");
   var parsed_date = new Date(values[2], values[1], values[0]);
                   $('.datepicker').datepicker({
                       minDate: parsed_date
                   }); 
   alert(parsed_date);

In alert message

    Mon Mar 17 2014 00:00:00 GMT+0530 (India Standard Time)
Was it helpful?

Solution

You don't need a new Date object. You have to replace the / with - in your string because your date format (dd mm yyyy) is already correct. Only the seperator for minDate is wrong.

var time_value = result.sdate;
var parsed_date = time_value.replace(/\//g, '-');
                $('.datepicker').datepicker({
                    minDate: parsed_date
                }); 
alert(parsed_date);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top