Home Java LocalDateTime Methods minusDays() Java LocalDateTime minusDays() Method 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.
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 Call What 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.time.LocalDateTime
public LocalDateTime minusDays(long days) Parameters Parameter Description days (long)The number of days to subtract. It can be zero or negative.
Return Value Return Value Description LocalDateTimeA new LocalDateTime with the days subtracted. The original is not changed.
Important
Going back, the month and the year change by themselves when needed: 1 March minus 1 day is the last day of February, which is 28 or 29 depending on the year. A LocalDateTime has no time zone, so there is no daylight saving rule, and the clock time never moves. If the result is before the earliest supported date, a DateTimeException is thrown.
Compare with Similar Methods Methods that move a date-time in time:
Java Examples 1. A week ago 2. Month and year boundary 3. Negative numbers 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.
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));
}
} today: 2026-03-15T09:00
yesterday: 2026-03-14T09:00
week ago: 2026-03-08T09:00 How It Works The report time. 15 March 2026 at 09:00.One day back. minusDays(1) gives the 14th at 09:00.Seven days back. minusDays(7) gives 8 March at 09:00.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.
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));
}
} 2 Mar 2026 - 3 days: 2026-02-27T08:00
1 Mar 2024 - 1 day: 2024-02-29T08:00
2 Jan 2027 - 5 days: 2026-12-28T08:00 How It Works Back into February. Three days before 2 March 2026 is 27 February, because February 2026 has 28 days.A leap year. The day before 1 March 2024 is 29 February.Back into the previous year. Five days before 2 January 2027 is 28 December 2026.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.
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));
}
} minusDays(-2): 2026-03-17T09:00
plusDays(2): 2026-03-17T09:00
same: true How It Works Subtracting a negative. Taking away minus two days is the same as adding two days.The date moves forward. minusDays(-2) gives 17 March.plusDays(2) agrees. Both objects hold the same date-time, so equals prints true.Frequently Asked Questions How do I subtract days from a LocalDateTime in Java? Call dt.minusDays(n). It returns a new LocalDateTime, so store it: dt = dt.minusDays(n).
Does minusDays() change the original LocalDateTime? No. LocalDateTime is immutable, so minusDays() returns a new object and leaves the original as it was.
Can I pass a negative number to minusDays()? Yes. A negative number moves the other way, so dt.minusDays(-n) gives the same result as dt.plusDays(n).
How do I get yesterday's date and time in Java? Use LocalDateTime.now().minusDays(1). It gives the same time of day, one day earlier.
How do I get the date 30 days ago in Java? Call dt.minusDays(30). The month and year roll back automatically.
About the author Developer, cloud engineer, and technical writer
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
Helpful Share Copy link Suggestion