I have these 3 date formats.
let dates = [
"25/03/2023",
"2023-03-25",
"03/25/2023",
];
I am trying to bring them to a single ‘dd-mm-yyy’ format but I am getting the following output.
function convertDate(date) {
let dateObj = new Date(date);
let day = dateObj.getDate().toString().padStart(2, '0');
let month = (dateObj.getMonth() + 1).toString().padStart(2, '0');
let year = fechaObj.getFullYear();
return `${day}-${month}-${year}`;
}
let newDates = dates.map((fecha) => convertDate(date));
console.log(newDates); // ['NaN-NaN-NaN', '24-03-2023', '25-03-2023']