Function formatDate

  • Formats a Date object into a string in the 'YYYY-MM-DD' format.

    Parameters

    • date: Date

      The Date object to format. Must be a valid Date instance.

    Returns string

    The formatted date string in 'YYYY-MM-DD' format.

    Will throw an error if the provided date is not a valid Date object.

    const result = formatDate(new Date());
    console.log(result); // "2025-09-22"