getDateByName function
Extracts the year, month, and day from a DateTime object and returns them as a named tuple.
This function formats the given DateTime object into a human-readable string for the year, month, and day.
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 DateTime object to be converted.
Returns a named tuple containing the year, month, and day as strings.
Example:
var dateInfo = getDateByName(DateTime(2023, 10, 5));
print(dateInfo); // Output: (year: 2023, month: October, day: 5)
Implementation
({String year, String month, String day}) getDateByName(DateTime date){
if(isEmpty(date)) return getDateByName(DateTime.now());
String monthName = DateFormat('MMMM').format(date);
String day = DateFormat('d').format(date);
String year = DateFormat('y').format(date);
var res= (year: year, month: monthName, day: day);
return res;
}