I want to create a function that converts all date formats into single date format (yyyy-mm-dd).
function taskDate(dt){
console.log(dt)
}
var dt = new Date("15-10-2022")
var d = dt.getDate();
var m = dt.getMonth() + 1;
var y = dt.getFullYear();
var dateString = y + '-' + (m <= 9 ? '0' + m : m) + "-" + (d <= 9 ? '0' + d : d);
taskDate(dateString)
the problem occurred in dd-mm-yyyy format its converts day into month automatically and when the day is more than 12 its returns, Nan.