stringToDateByName function
Converts a string representation of a date to a named tuple containing the year, month, and day.
This function first converts the given date string into a DateTime object using the specified format.
It then extracts the year, month, and day from the DateTime object and returns them as a named tuple.
The month is returned as its full name (e.g., January, February), the day as a numeric value, and the year as a numeric value.
[date] - The date string to be converted. [format] - The format of the date string. Defaults to 'yyyy-MM-dd'.
Returns a named tuple containing the year, month, and day as strings.
Example:
var dateInfo = stringToDateByName('2023-10-05');
print(dateInfo); // Output: (year: 2023, month: October, day: 5)
Implementation
({String year, String month, String day}) stringToDateByName(String date, {String format = 'yyyy-MM-dd'}) {
var dateTime = stringToDate(date, format: format);
return getDateByName(dateTime);
}