daysInMonth property

int get daysInMonth

Returns the number of days in this date's month.

DateTime(2024, 2).daysInMonth // 29 (leap year)
DateTime(2023, 2).daysInMonth // 28

Implementation

int get daysInMonth =>
    DateTime(year, month + 1).subtract(const Duration(days: 1)).day;