int getNumberOfWeeks(int year, int month) { DateTime lastDayOfMonth = DateTime(year, month + 1, 0); return ((lastDayOfMonth.day + lastDayOfMonth.weekday - 1) / 7) .ceil(); }