Java LocalDateTime minusDays() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Java 8+

Definition

In Java, minusDays(days) returns a new LocalDateTime that is the given number of days earlier than the original. The time of day stays exactly the same.

LocalDateTime is immutable, so the original object never changes. Always keep the result: dt = dt.minusDays(1);. This is how you find "yesterday", "a week ago", or the start of a reporting period.

An instance method of java.time.LocalDateTime (since Java 8): call it on a LocalDateTime object. Add import java.time.LocalDateTime; at the top of your file.

Syntax

Call it on a LocalDateTime and pass the number of days. A negative number goes the other way.

Java
LocalDateTime start = LocalDateTime.of(2026, 3, 15, 9, 0);
LocalDateTime result = start.minusDays(7);   // 2026-03-08T09:00
System.out.println(start);   // 2026-03-15T09:00
CallWhat it does
dt.minusDays(n)Returns a new date-time with n days subtracted.
dt.plusDays(n)The same idea in the opposite direction.
dt.minus(n, ChronoUnit.DAYS)The general form. It does the same thing for this unit.
date.minusDays(n)LocalDate has the same method, but it has no time of day.

The result is a new object. Calling minusDays() without using the returned value does nothing useful.

Library declarations
Java
// java.time.LocalDateTime
public LocalDateTime minusDays(long days)

Parameters

ParameterDescription
days (long)The number of days to subtract. It can be zero or negative.

Return Value

Return ValueDescription
LocalDateTimeA new LocalDateTime with the days subtracted. The original is not changed.

Compare with Similar Methods

Methods that move a date-time in time:

MethodHow it differs
plusDays(n)The opposite direction for days.
minus(n, unit)The general method: you choose the unit as an argument.
minusWeeks(n)Subtracts whole weeks, 7 days each.
minusHours(n)Subtracts hours instead of days.

Java Examples

Example 1 — Look Back One Week and One Day

A report is run on 15 March at 09:00. Print the same moment 7 days ago and 1 day ago.

Java
import java.time.LocalDateTime;

public class LdtMinusDaysDemo {
    public static void main(String[] args) {
        LocalDateTime today = LocalDateTime.of(2026, 3, 15, 9, 0);

        System.out.println("today:     " + today);
        System.out.println("yesterday: " + today.minusDays(1));
        System.out.println("week ago:  " + today.minusDays(7));
    }
}

How It Works

  1. The report time. 15 March 2026 at 09:00.
  2. One day back. minusDays(1) gives the 14th at 09:00.
  3. Seven days back. minusDays(7) gives 8 March at 09:00.
  4. The original stays the same. Each call builds a new object, so today still holds the 15th.

Example 2 — Go Back Across a Month and a Year

Subtract days from early March, from 1 March in a leap year, and from early January.

Java
import java.time.LocalDateTime;

public class LdtMinusDaysBoundary {
    public static void main(String[] args) {
        LocalDateTime march = LocalDateTime.of(2026, 3, 2, 8, 0);
        LocalDateTime leap = LocalDateTime.of(2024, 3, 1, 8, 0);
        LocalDateTime jan = LocalDateTime.of(2027, 1, 2, 8, 0);

        System.out.println("2 Mar 2026 - 3 days: " + march.minusDays(3));
        System.out.println("1 Mar 2024 - 1 day:  " + leap.minusDays(1));
        System.out.println("2 Jan 2027 - 5 days: " + jan.minusDays(5));
    }
}

How It Works

  1. Back into February. Three days before 2 March 2026 is 27 February, because February 2026 has 28 days.
  2. A leap year. The day before 1 March 2024 is 29 February.
  3. Back into the previous year. Five days before 2 January 2027 is 28 December 2026.
  4. The time stays at 08:00. Only the date part changes.

Example 3 — Pass a Negative Number

Subtract -2 days, and compare the result with adding 2 days.

Java
import java.time.LocalDateTime;

public class LdtMinusDaysNegative {
    public static void main(String[] args) {
        LocalDateTime start = LocalDateTime.of(2026, 3, 15, 9, 0);

        LocalDateTime viaMinus = start.minusDays(-2);
        LocalDateTime viaPlus = start.plusDays(2);

        System.out.println("minusDays(-2): " + viaMinus);
        System.out.println("plusDays(2):   " + viaPlus);
        System.out.println("same: " + viaMinus.equals(viaPlus));
    }
}

How It Works

  1. Subtracting a negative. Taking away minus two days is the same as adding two days.
  2. The date moves forward. minusDays(-2) gives 17 March.
  3. plusDays(2) agrees. Both objects hold the same date-time, so equals prints true.

Frequently Asked Questions

Call dt.minusDays(n). It returns a new LocalDateTime, so store it: dt = dt.minusDays(n).
No. LocalDateTime is immutable, so minusDays() returns a new object and leaves the original as it was.
Yes. A negative number moves the other way, so dt.minusDays(-n) gives the same result as dt.plusDays(n).
Use LocalDateTime.now().minusDays(1). It gives the same time of day, one day earlier.
Call dt.minusDays(30). The month and year roll back automatically.

Next: minusHours()

Return a copy that is a number of hours earlier.

minusHours() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

13 people found this page helpful