How can I check for month-to-month changes between dates?
For example:
DateTime a = DateTime(2022, 10, 01);
DateTime b = DateTime(2022, 09, 22);
if (...)
print(isChange);
Output: true.
If:
DateTime a = DateTime(2022, 09, 24);
DateTime b = DateTime(2022, 09, 22);
if (...)
print(isChange);
Output: false.
>Solution :
You can use this function:
bool isChange(DateTime a, DateTime b) {
return a.month != b.month || a.year != b.year;
}
and use it like this:
DateTime a = DateTime(2022, 09, 24);
DateTime b = DateTime(2022, 09, 22);
print("ischange = ${isChange(a, b)}"); //ischange = false