getDateFormatByDate function

String getDateFormatByDate(
  1. DateTime date
)

Formats a DateTime object into a string in YYYY-MM-DD format.

Pads month and day with leading zeros if needed.

Example:

String formatted = getDateFormatByDate(DateTime(2025, 6, 12)); // "2025-06-12"

Returns a string representation of the date in YYYY-MM-DD format.

Implementation

String getDateFormatByDate(DateTime date) {
  return "${date.year.toString()}-${date.month.toString().padLeft(2, '0')}-${date.day.toString().padLeft(2, '0')}";
}