Encodera

Thanks for reading!

Donate to the site — we work hard for you.

How to add days to a date

Short answer

plusDays() returns a new date shifted by the given number of days:

void main() {
    var order = LocalDate.of(2026, 3, 8);
    var delivery = order.plusDays(5);
 
    IO.println(delivery);
}

Output:

2026-03-13

Months, weeks, years

There are similar methods for every unit. Negative values and minus...() move backwards:

void main() {
    var date = LocalDate.of(2026, 3, 8);
 
    IO.println(date.plusWeeks(2));
    IO.println(date.plusMonths(1));
    IO.println(date.minusYears(1));
    IO.println(date.minusDays(10));
}

Output:

2026-03-22
2026-04-08
2025-03-08
2026-02-26

The end of a month

If the new month has no such day, Java takes the last day of the month:

void main() {
    IO.println(LocalDate.of(2026, 1, 31).plusMonths(1));
}

Output:

2026-02-28

Working days

To skip weekends, add one day at a time and check the day of the week:

LocalDate addWorkingDays(LocalDate date, int days) {
    var result = date;
    int added = 0;
    while (added < days) {
        result = result.plusDays(1);
        if (result.getDayOfWeek() != DayOfWeek.SATURDAY && result.getDayOfWeek() != DayOfWeek.SUNDAY) {
            added++;
        }
    }
    return result;
}
 
void main() {
    IO.println(addWorkingDays(LocalDate.of(2026, 3, 6), 3));
}

Output:

2026-03-11

Common mistake

Calling plusDays() without keeping the result. LocalDate is immutable — the method does not change the date, it returns a new one:

void main() {
    var date = LocalDate.of(2026, 3, 8);
    date.plusDays(5);
 
    IO.println(date);
}

Output:

2026-03-08

Functions used in this recipe

  • LocalDate.plusDays() — Returns a date the given number of days later. Related: minusDays(), plusWeeks(), plusMonths(), plusYears().
  • LocalDate.of() — Creates a date from a year, month and day.

Thanks for reading!

Donate to the site — we work hard for you.