There is a function in my code that accepts dates in different formats. It can handle two formats:
2022-06-04
or
04/06/2022
I want all dates to be in the format:
2022-06-04
For instance:
public getMaxduration(data: object[]): number {
data.forEach((line) => {
const periodFrom = new Date(line['period_to'];
const periodTo = new Date(line['period_from'];
console.log(periodFrom);
console.log(periodTo);
})
}
The issue I'm facing is when a date is provided in the dd/mm/yyyy format, it causes problems. How can I ensure all dates within this function are formatted as yyyy-mm-dd?