I am creating whole year calender, How to get numbers of days of month in Flutter? e.g., January -> 31, Fabruary -> 28/29(as per year), March -> 31 So on...
Using date1.difference(date2).inDays is NOT correct. For some dates it will return incorrect results, like for DateTime(2020, 3).
This is because the Duration is based on seconds calculations. And inDays implementation is build with assumption that days are always have the same number of seconds (_duration ~/ Duration.microsecondsPerDay) which is not true.
But instead of this you can just use:
DateTime(date.year, date.month + 1, 0).day
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With