I have the following code, with the aim of changing the format of a date from "18/11/2020" to "2020-11-18":
var dateSearched = $("#InputDate").val(); // prints "18/11/2020"
var dateObject = new Date(dateSearched);
var formattedDate = dateObject.toISOString().split('T')[0];
The issue is that the dateObject
has an error of Invalid Date.
When debugging dateSearched
is formatted as a string "18/11/2020", although when hovering over the variable in my code, it says (local var) dateSearched: string | number | string []
which I suspect might be the cause? I tried using dateSearched.toString()
but this does not work.
Can anyone point me in the right direction please?