Java LocalDateTime minusMonths() Method

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

Definition

In Java, minusMonths(months) returns a new LocalDateTime that is the given number of months earlier than the original. The year goes back by itself when the months pass January, and the time of day stays the same.

LocalDateTime is immutable, so the original object never changes. Always keep the result: dt = dt.minusMonths(1);. Months have different lengths, so this method has one special rule, explained under "Important" below.

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 months. A negative number goes the other way.

Java
LocalDateTime start = LocalDateTime.of(2026, 3, 15, 8, 0);
LocalDateTime result = start.minusMonths(2);   // 2026-01-15T08:00
System.out.println(start);   // 2026-03-15T08:00
CallWhat it does
dt.minusMonths(n)Returns a new date-time with n months subtracted.
dt.plusMonths(n)The same idea in the opposite direction.
dt.minus(n, ChronoUnit.MONTHS)The general form. It does the same thing for this unit.
date.minusMonths(n)LocalDate has the same method, with the same end-of-month rule.

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

Library declarations
Java
// java.time.LocalDateTime
public LocalDateTime minusMonths(long months)

Parameters

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

Return Value

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

Compare with Similar Methods

Methods that move a date-time in time:

MethodHow it differs
plusMonths(n)The opposite direction for months.
minus(n, unit)The general method: you choose the unit as an argument.
minusYears(n)Subtracts whole years, which keeps the month and day.
minusDays(n)Subtracts exact days, with no end-of-month rule.

Java Examples

Example 1 — Find the Same Moment in Earlier Months

A report runs on 15 March. Print the same moment 1, 3, and 12 months earlier.

Java
import java.time.LocalDateTime;

public class LdtMinusMonthsDemo {
    public static void main(String[] args) {
        LocalDateTime now = LocalDateTime.of(2026, 3, 15, 8, 0);

        System.out.println("1 month ago:   " + now.minusMonths(1));
        System.out.println("3 months ago:  " + now.minusMonths(3));
        System.out.println("12 months ago: " + now.minusMonths(12));
    }
}

How It Works

  1. The starting moment. 15 March 2026 at 08:00.
  2. One month back. The day stays 15 and the month becomes February.
  3. Three months back. March minus three months goes into the previous year, giving 15 December 2025.
  4. Twelve months back. The result is 15 March 2025, exactly one year earlier.

Example 2 — See the End-of-Month Rule Going Back

Subtract one month from the 31st of March, from 30 March in a leap year, and from 31 May.

Java
import java.time.LocalDateTime;

public class LdtMinusMonthsEnd {
    public static void main(String[] args) {
        LocalDateTime mar31 = LocalDateTime.of(2026, 3, 31, 9, 0);
        LocalDateTime mar30 = LocalDateTime.of(2024, 3, 30, 9, 0);
        LocalDateTime may31 = LocalDateTime.of(2026, 5, 31, 9, 0);

        System.out.println("31 Mar 2026 - 1 month: " + mar31.minusMonths(1));
        System.out.println("30 Mar 2024 - 1 month: " + mar30.minusMonths(1));
        System.out.println("31 May 2026 - 1 month: " + may31.minusMonths(1));
    }
}

How It Works

  1. February 2026 is short. It has no 31st, so 31 March minus 1 month becomes 28 February.
  2. Leap year. February 2024 has 29 days, so 30 March minus 1 month becomes 29 February.
  3. April has 30 days. 31 May minus 1 month becomes 30 April.
  4. No error. Java chooses the last valid day, so your program keeps running.

Example 3 — Compare Months with Years

Subtract 12 months and 1 year and compare them, then subtract 18 months.

Java
import java.time.LocalDateTime;

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

        LocalDateTime byMonths = start.minusMonths(12);
        LocalDateTime byYears = start.minusYears(1);

        System.out.println("12 months: " + byMonths);
        System.out.println("1 year:    " + byYears);
        System.out.println("same:      " + byMonths.equals(byYears));
        System.out.println("18 months: " + start.minusMonths(18));
    }
}

How It Works

  1. 12 months is one year. minusMonths(12) gives 15 March 2025.
  2. minusYears(1) agrees. Both objects are equal, so the third line prints true.
  3. 18 months is a year and a half. The result is 15 September 2024, which shows how the year and month both change.

Frequently Asked Questions

Call dt.minusMonths(n). It returns a new LocalDateTime, so store it: dt = dt.minusMonths(n).
No. LocalDateTime is immutable, so minusMonths() returns a new object and leaves the original as it was.
Yes. A negative number moves the other way, so dt.minusMonths(-n) gives the same result as dt.plusMonths(n).
28 February in a normal year and 29 February in a leap year, because Java uses the last valid day of February.
Use dt.minusMonths(1). If last month is shorter and has no such day, you get its last day.

Next: minusNanos()

Return a copy that is a number of nanoseconds earlier.

minusNanos() 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.

7 people found this page helpful