Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9015425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:44:52+00:00 2026-06-16T03:44:52+00:00

When comparing two dates with date before method, if the dates are similar, it

  • 0

When comparing two dates with date before method, if the dates are similar, it returns false as follows:

  • date1: Tue Dec 18 00:00:00 GMT+02:00 2012
  • date2: Tue Dec 18 00:00:00 GMT+02:00 2012

the method date1.before(date2) always returns false in this case, which does not make sense to me (doesn’t apply to my case in other words).
I want to check if a date (day/month/year) equals today’s date (day/month/year)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T03:44:53+00:00Added an answer on June 16, 2026 at 3:44 am

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to add custom validator for comparing two dates - start date and
I am trying to compare two dates. My first date is: Date previousDate =Returns
I am comparing two dates and trying to determine the max of the two
Possible Duplicates: Comparing dates How to compare two dates in Objective-C i want to
I am comparing two dates in javascript function checkCurrentDate(expiryDate){ //var currentDateStr=expiryDate; var currentDate =
I want to compare two dates in PHP. One date is the date due,
Possible Duplicate: How can I calculate the difference between two dates? NSDate, comparing two
I am comparing the date when a file was last modified for two files,
I am new to iPhone developer, i want to compare two Dates, first date
I'm comparing two dates and my code goes like this. jQuery('.newAppointment a.ui-state-default').click(function() { var

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.