I have a page with a number of variables that contain a date in string format (yyyy-mm-dd) which originates from using moment.js.
I am not interested in the time so as long as I can get the date converted to a date object that would be great.
I tried the following but this doesn't work and I couldn't find a way using moment.js:
var newVar = new Date(dateVar);
first of all i will say following should work for you..
var dateVar = "2010-10-30"; var d=new Date(dateVar);
if you say above not working check the below one -
var dateVar = "2010-10-30"; var dsplit = dateVar.split("-"); var d=new Date(dsplit,dsplit-1,dsplit);
for the proof check the jsfiddle.. both is working fine.. JSFiddle