I have a date in this format "DD/MM/YYYY" when I try new Date("23/06/2019")
I get the following error:
"Invalid Date"
how can I fix?
I have a date in this format "DD/MM/YYYY" when I try new Date("23/06/2019")
I get the following error:
"Invalid Date"
how can I fix?
The string you pass in isn't something the Date 'constructor' knows how to deal with. Look at how to create a date object with javascript (Here's a SO post).
You can try this as a quick fix for now:
let yourDate = "23/06/2019".split('/');
new Date(yourDate[2], yourDate[1], yourDate[0]);
or
let yourDate = "23/06/2019".split('/').reverse().join('-');
new Date(yourDate);
I would recommend using the moment.js library for date parsing. You could easily parse your date string.
https://momentjs.com/docs/#/parsing/string-format/
moment(„23/09/2019“,“DD-MM-YYYY“)