Formats a Date object into a string in the 'YYYY-MM-DD' format.
The Date object to format. Must be a valid Date instance.
The formatted date string in 'YYYY-MM-DD' format.
Will throw an error if the provided date is not a valid Date object.
date
const result = formatDate(new Date());console.log(result); // "2025-09-22" Copy
const result = formatDate(new Date());console.log(result); // "2025-09-22"
Formats a Date object into a string in the 'YYYY-MM-DD' format.