How to Sort List of Date String in Ascending Order:
void main() {
List<String> datestrings = [
"2022-02-12",
"2022-01-23",
"2022-12-11",
"2022-01-14",
];
datestrings.sort((a, b){ //sorting in ascending order
return DateTime.parse(a).compareTo(DateTime.parse(b));
});
print(datestrings);
}
OutPut:
output: [2010-01-23, 2013-01-14, 2020-02-12, 2021-12-11]
How to Sort List of Date String in Descending Order:
void main() {
List<String> datestrings = [
"2022-02-12",
"2022-01-23",
"2022-12-11",
"2022-01-14",
];
datestrings.sort((a, b){ //sorting in descending order
return DateTime.parse(b).compareTo(DateTime.parse(a));
});
print(datestrings);
}
OutPut:
[2022-12-11, 2022-02-12, 2022-01-23, 2022-01-14]

I’m Abhishek, a DevOps, SRE, DevSecOps, and Cloud expert with a passion for sharing knowledge and real-world experiences. I’ve had the opportunity to work with Cotocus and continue to contribute to multiple platforms where I share insights across different domains:
-
DevOps School – Tech blogs and tutorials
-
Holiday Landmark – Travel stories and guides
-
Stocks Mantra – Stock market strategies and tips
-
My Medic Plus – Health and fitness guidance
-
TrueReviewNow – Honest product reviews
-
Wizbrand – SEO and digital tools for businesses
I’m also exploring the fascinating world of Quantum Computing.