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.
Is there a way I can pass such a variable to a Javascript date object resp. to convert it to a Javascript date object ? 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);
Many thanks for any help with this, Tim.
To solve this problem I a made function who manage the change from text to date:
My examples works with date as this: Jun/1/2016 to 2016-06-01 you can rebuild the function to make your format works...
The cero's at the left of the numbers are added to match the date type format.
console.log()
has been use to show the output , run this and you will understand the codefirst of all i will say following should work for you..
if you say above not working check the below one -
for the proof check the jsfiddle.. both is working fine.. JSFiddle