countWeeks method
Counts the number of weeks between the current DateTime and the differenceDateTime
.
Returns an integer representing the number of weeks. This function truncates to the lowest week.
Example:
DateTime date1 = DateTime(2023, 1, 1);
DateTime date2 = DateTime(2023, 10, 16);
int weeksDifference = date1.countWeeks(date2);
print('Weeks difference: $weeksDifference'); // Output: Weeks difference: 41
Implementation
int countWeeks(DateTime? differenceDateTime) {
int difference =
(differenceDateTime ?? DateTime.now()).millisecondsSinceEpoch -
millisecondsSinceEpoch;
int count = (difference / 604800000).truncate();
/* if (count > 3) {
// return '1 month';
return 1;
}*/
// return count.toString() + (count > 1 ? ' weeks' : ' week');
return count;
}