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

How to get the amount of days between two datetime objects in flutter

I want to find the difference in days between two different datetimes in flutter.

in other words, i want to subtract two dates and get the difference between them
I found a way to do this in c# here. But unfortunately this doesn’t apply for flutter.

Any help is appreciated

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

>Solution :

You can use difference method of DateTime class to get the duration between two dates in dart.

 DateTime date1 = new DateTime.now();
 DateTime date2 = DateTime(2021, 1, 1);
 print(date1.difference(date2).inDays); // Prints 356 days
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