As date1.equals(date2), it is normal that date1.before(date2) returns false. As will do date1.after(date2).

Both dates are the same, so one is not before the other.

From the javadoc :

true if and only if the instant of time represented by this Date object is strictly earlier than the instant represented by when; false otherwise.

Try something like:

if (date1.before(date2) || date1.equals(date2)) ...

The answers provided below suggest testing for the inverse, and they're right:

if (!date1.after(date2)) ...

Both tests are equivalent.

Answer from xlecoustillier on Stack Overflow
🌐
TutorialsPoint
tutorialspoint.com › java › util › date_before.htm
Java Date before() Method
The Java Date before(Date when) method checks if this date is before the specified date. Following is the declaration for java.util.Date.before() method when − date to be checked true if the represented Date object is strictly before than the
🌐
W3Resource
w3resource.com › java-tutorial › util › date › java_date_before.php
Java Date before() Method - w3resource
The following example fills a Date before(Date when) . import java.util.*; public class Main { public static void main(String[] args) { // create 2 dates Date dt1 = new Date(2017, 3, 31); Date dt2 = new Date(2017, 5, 14); // Check if dt1 is before dt2 boolean result = dt1.before(dt2); System.out.println("Date1 is before date2: " + result); // Check if dt2 is after dt1 result = dt2.before(dt1); System.out.println("Date2 is before date1: " + result); } }
🌐
Codecademy
codecademy.com › docs › java › date › .before()
Java | Date | .before() | Codecademy
July 29, 2023 - The Date.before() method checks whether a date occurs before another specified date, and returns a boolean value. ... Looking for an introduction to the theory behind programming?
🌐
GeeksforGeeks
geeksforgeeks.org › java › date-before-method-in-java-with-examples
Date before() method in Java with Examples - GeeksforGeeks
December 26, 2025 - Date.before() method in Java checks if one date occurs before another specified date. It returns true if the calling date is earlier, and false otherwise. If the specified date is null, it throws a "NullPointerException".
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › util › Date.html
Date (Java Platform SE 7 )
This Date object is modified so ... same as before, as interpreted in the local time zone. ... Deprecated. As of JDK version 1.1, replaced by Calendar.get(Calendar.SECOND). Returns the number of seconds past the minute represented by this date. The value returned is between 0 and 61. The values 60 and 61 can only occur on those Java Virtual Machines ...
🌐
IncludeHelp
includehelp.com › java › date-before-method-with-example.aspx
Java Date before() Method with Example
The return type of this method is boolean, it returns true when this date is before the given Date (d) otherwise it returns false. ... // Java program to demonstrate the example // of boolean before() method of Date import java.util.*; public class BeforeDate { public static void main(String[] ...
🌐
Tutorjoes
tutorjoes.in › Java_example_programs › get_date_before_and_after_1year_compares_to_current_date_in_java
Write a Java program to get a date before and after 1 year compares to the current date
Current Date : Sat Nov 05 13:41:16 IST 2022 Date Before One Year : Fri Nov 05 13:41:16 IST 2021 Date After One Year : Sun Nov 05 13:41:16 IST 2023
Find elsewhere
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › Date.html
Date (Java Platform SE 8 )
October 20, 2025 - This Date object is modified so that it represents a point in time within the specified minute of the hour, with the year, month, date, hour, and second the same as before, as interpreted in the local time zone. ... Deprecated. As of JDK version 1.1, replaced by Calendar.get(Calendar.SECOND). Returns the number of seconds past the minute represented by this date. The value returned is between 0 and 61. The values 60 and 61 can only occur on those Java Virtual Machines that take leap seconds into account.
🌐
Mkyong
mkyong.com › home › java › how to compare dates in java
How to compare dates in Java - Mkyong.com
March 26, 2021 - date1 : 2020-01-30 date2 : 2020-01-31 result: -1 Date1 is before Date2 · Change the date1 to 2020-01-31. Output · Terminal · date1 : 2020-01-31 date2 : 2020-01-31 result: 0 Date1 is equal to Date2 · Change the date1 to 2020-02-01. Output · Terminal · date1 : 2020-02-01 date2 : 2020-01-31 result: 1 Date1 is after Date2 · Below is a more user friendly method to compare two java.util.Date in Java.
🌐
Stack Abuse
stackabuse.com › how-to-compare-dates-in-java
How to Compare Dates in Java
February 28, 2023 - LocalDate class is one of the most commonly used classes of java.time, alongside LocalTime and LocalDateTime. It represents a date without time or time zone fields with a default date format of yyyy-mm-dd. The built-in methods for comparison are pretty similar to the Date class: ... All three methods check if the invoked LocalDate is before, after, or equal to the argument, returning boolean values respectively.
🌐
Java67
java67.com › 2016 › 09 › how-to-compare-two-dates-in-java.html
How to Compare Two Dates in Java? Check If They Are Equal, Later or Earlier - Examples | Java67
If you are looking to find out whether a date comes before or after another date then you have 3 choices, you can use the compareTo() method of java.util.Date class, or you can use before() and after() method of Date class, or you can use before() ...
🌐
Classpath
developer.classpath.org › doc › java › util › Date-source.html
Source for java.util.Date (GNU Classpath 0.95 Documentation)
319: * 320: * @param when the other date 321: * @return true, if the date represented by when is strictly later 322: * than the time represented by this object. 323: */ 324: public boolean before(Date when) 325: { 326: return time < when.time; 327: } 328: 329: /** 330: * Compares two dates for equality.
🌐
Medium
medium.com › javarevisited › date-time-api-before-java-8-78425150e594
Understanding Date & Time API before java 8 | by Hamza Nassour | Javarevisited | Medium
July 19, 2023 - In Java 7 and earlier versions, the Date and Calendar classes in the java.util package were used to handle date and time. However, these classes had some limitations , leading to the introduction of the more modern java.time package in Java 8.
🌐
W3Schools
w3schools.com › java › java_date.asp
Java Date and Time
import java.time.LocalDateTime; // Import the LocalDateTime class import java.time.format.DateTimeFormatter; // Import the DateTimeFormatter class public class Main { public static void main(String[] args) { LocalDateTime myDateObj = LocalDateTime.now(); System.out.println("Before formatting: " + myDateObj); DateTimeFormatter myFormatObj = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss"); String formattedDate = myDateObj.format(myFormatObj); System.out.println("After formatting: " + formattedDate); } } The output will be: Try it Yourself » ·
🌐
Tpoint Tech
tpointtech.com › java-date-before-method
Java Date before() Method - Tpoint Tech
March 17, 2025 - The before() method of Java Date class tests whether the date is before the specified date or not.
🌐
How to do in Java
howtodoinjava.com › home › java date time › calculate next and previous date in java
Calculate Next and Previous Date in Java
April 7, 2023 - private static final long MILLIS_IN_A_DAY = 1000 * 60 * 60 * 24; private static Date findNextDay(Date date) { return new Date(date.getTime() + MILLIS_IN_A_DAY); } private static Date findPrevDay(Date date) { return new Date(date.getTime() - MILLIS_IN_A_DAY); } import java.time.LocalDate; import java.util.Date; public class FindNextPrevDay { private static final long MILLIS_IN_A_DAY = 1000 * 60 * 60 * 24; public static void main(String[] args) { Date today = new Date(); System.out.println("Today :: " + findNextDay(today)); System.out.println("Next date :: " + findNextDay(today)); System.out.pri
🌐
GeeksforGeeks
geeksforgeeks.org › java › date-after-method-in-java
Date after() method in Java - GeeksforGeeks
November 7, 2019 - Below programs illustrate after() method in Date class: Program 1: ... // Java code to demonstrate // after() function of Date class import java.util.Date; import java.util.Calendar; public class GfG { // main method public static void main(String[] args) { // creating a Calendar object Calendar c = Calendar.getInstance(); // set Month // MONTH starts with 0 i.e.
🌐
Mkyong
mkyong.com › home › java8 › java – check if the date is older than 30 days or 6 months
Java – Check if the date is older than 30 days or 6 months - Mkyong.com
March 26, 2021 - package com.mkyong.app; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.GregorianCalendar; public class JavaCalendarExample { private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); public static void main(String[] args) { Calendar sixMonthsAgo = Calendar.getInstance(); // Current date // 2021-03-26 System.out.println("now: " + sdf.format(sixMonthsAgo.getTime())); // old way to minus 6 months // 2020-09-26 sixMonthsAgo.add(Calendar.MONTH, -6); System.out.println("sixMonthsAgo: " + sdf.format(sixMonthsAgo.getTime())); // 2019-06-10 Calendar date1