weekNumberInMonth property
Week number within the month (1-based). First partial week is 1. Audited: 2026-06-12 11:26 EDT
Implementation
@useResult
int get weekNumberInMonth {
final int dayOfMonth = day;
// ignore: saropa_lints/avoid_datetime_constructor -- year/month from this valid DateTime; the omitted day defaults to 1, which exists in every month
final DateTime first = DateTime(year, month);
final int firstWeekday = first.weekday;
// weekday is Mon=1..Sun=7, so 8 - weekday gives remaining days in week 1
final int daysInFirstWeek = 8 - firstWeekday;
if (dayOfMonth <= daysInFirstWeek) return 1;
return ((dayOfMonth - daysInFirstWeek - 1) / 7).floor() + 2;
}