calculateDaysBetweenTwoDates function

int calculateDaysBetweenTwoDates(
  1. DateTime startDate,
  2. DateTime endDate
)

Calculates the number of days between two DateTime objects.

This function computes the difference in days between the provided start and end dates. It returns the number of full days between the two dates.

[startDate] - The start date as a DateTime object. [endDate] - The end date as a DateTime object.

Returns the number of days between the start and end dates as an integer.

Example:

int days = calculateDaysBetweenTwoDates(DateTime(2023, 10, 1), DateTime(2023, 10, 5));
print(days); // Output: 4

Implementation

int calculateDaysBetweenTwoDates(DateTime startDate, DateTime endDate) {
  return endDate.difference(startDate).inDays;
}