addDays method

DateTime addDays(
  1. int amount
)

Adds a certain amount of days to this date and returns a new DateTime instance.

Example:

DateTime currentDate = DateTime(2022, 1, 8);
DateTime futureDate = currentDate.addDays(5);
print(futureDate);  // 2022-01-13 00:00:00.000

The addDays method creates a new DateTime instance by adding the specified number of days to the original date. The time components (hour, minute, second, millisecond, microsecond) remain unchanged.

Implementation

DateTime addDays(int amount) => DateTime(
      year,
      month,
      day + amount,
      hour,
      minute,
      second,
      millisecond,
      microsecond,
    );