Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Flutter check for month changes in dates

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading