Java LocalDateTime minusYears() Method

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

Definition

In Java, minusYears(years) returns a new LocalDateTime that is the given number of years earlier than the original. The month, the day, and the time of day stay the same.

LocalDateTime is immutable, so the original object never changes. Always keep the result: dt = dt.minusYears(1);. There is one exception: 29 February, 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 years. A negative number goes the other way.

Java
LocalDateTime start = LocalDateTime.of(2026, 3, 15, 10, 30);
LocalDateTime result = start.minusYears(3);   // 2023-03-15T10:30
System.out.println(start);   // 2026-03-15T10:30
CallWhat it does
dt.minusYears(n)Returns a new date-time with n years subtracted.
dt.plusYears(n)The same idea in the opposite direction.
dt.minus(n, ChronoUnit.YEARS)The general form. It does the same thing for this unit.
date.minusYears(n)LocalDate has the same method, with the same leap-day rule.

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

Library declarations
Java
// java.time.LocalDateTime
public LocalDateTime minusYears(long years)

Parameters

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

Return Value

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

Compare with Similar Methods

Methods that move a date-time in time:

MethodHow it differs
plusYears(n)The opposite direction for years.
minus(n, unit)The general method: you choose the unit as an argument.
minusMonths(n)Subtracts months, so minusMonths(12) equals minusYears(1).
minusDays(n)Subtracts exact days, so a year may be 365 or 366 of them.

Java Examples

Example 1 — Find the Same Moment Years Ago

Print the same date and time 1, 10, and 20 years before 15 March 2026.

Java
import java.time.LocalDateTime;

public class LdtMinusYearsDemo {
    public static void main(String[] args) {
        LocalDateTime now = LocalDateTime.of(2026, 3, 15, 10, 30);

        System.out.println("1 year ago:   " + now.minusYears(1));
        System.out.println("10 years ago: " + now.minusYears(10));
        System.out.println("20 years ago: " + now.minusYears(20));
    }
}

How It Works

  1. The starting moment. 15 March 2026 at 10:30.
  2. Only the year changes. minusYears(1) gives 2025, with the same month, day, and time.
  3. Bigger steps work the same way. 10 years back is 2016, and 20 years back is 2006.

Example 2 — Go Back from 29 February

Start on 29 February 2028 and subtract 1, 4, and 28 years.

Java
import java.time.LocalDateTime;

public class LdtMinusYearsLeap {
    public static void main(String[] args) {
        LocalDateTime leapDay = LocalDateTime.of(2028, 2, 29, 12, 0);

        System.out.println("-1 year:   " + leapDay.minusYears(1));
        System.out.println("-4 years:  " + leapDay.minusYears(4));
        System.out.println("-28 years: " + leapDay.minusYears(28));
    }
}

How It Works

  1. 2027 is not a leap year. One year back has no 29 February, so Java uses 28 February 2027.
  2. 2024 is a leap year. Four years back the leap day exists again.
  3. 2000 is a leap year too. It is divisible by 400, so 28 years back gives 29 February 2000.

Example 3 — Check if Someone Is at Least 18

Subtract 18 years from the current moment, and test a birth date against that cut-off.

Java
import java.time.LocalDateTime;

public class LdtMinusYearsAge {
    public static void main(String[] args) {
        LocalDateTime now = LocalDateTime.of(2026, 3, 15, 9, 0);
        LocalDateTime cutoff = now.minusYears(18);
        LocalDateTime born = LocalDateTime.of(2008, 3, 15, 0, 0);

        System.out.println("cut-off:      " + cutoff);
        System.out.println("born:         " + born);
        System.out.println("18 or older:  " + born.isBefore(cutoff));
    }
}

How It Works

  1. The cut-off. minusYears(18) gives 15 March 2008 at 09:00. Anyone born before this moment is at least 18.
  2. The birth moment. This person was born at midnight on 15 March 2008.
  3. isBefore decides. Midnight is earlier than 09:00 on the same day, so the answer is true.

Frequently Asked Questions

Call dt.minusYears(n). It returns a new LocalDateTime, so store it: dt = dt.minusYears(n).
No. LocalDateTime is immutable, so minusYears() returns a new object and leaves the original as it was.
Yes. A negative number moves the other way, so dt.minusYears(-n) gives the same result as dt.plusYears(n).
28 February of the earlier year, because that year is not a leap year. Four years back it is 29 February again.
Call dt.minusYears(1). The month, day, and time stay the same (except 29 February).

Next: now()

Get the current date and time from the system clock.

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

11 people found this page helpful