daysDifferenceTo method

int daysDifferenceTo([
  1. DateTime? other
])

Calculates the absolute difference in whole days between this DateTime and another DateTime (or the current time if none is provided). Ignores hours, minutes, seconds, and milliseconds.

Implementation

int daysDifferenceTo([DateTime? other]) {
  final comparisonDate = other ?? DateTime.now();
  return DateTime(year, month, day)
      .difference(DateTime(
          comparisonDate.year, comparisonDate.month, comparisonDate.day))
      .inDays
      .abs(); // Ensure positive result
}