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

  • SEARCH
  • Home
  • 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 9135633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:51:00+00:00 2026-06-17T08:51:00+00:00

Codes for getting current date: SimpleDateFormat sdfDate = new SimpleDateFormat(yyyy-MM-dd); Date now = new

  • 0

Codes for getting current date:

SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");
Date now = new Date();
String strDate = sdfDate.format(now);
return strDate;

Codes to search date and return result

try
   {     
        String x = cDate();

        ps = conn.prepareStatement(fill);
        rs = ps.executeQuery();

        int count = 0;

       while (rs.next()){
       Date dDate = rs.getDate("recDate");

        if (x.equals(dDate)){
            System.out.println("True);
            break;
        } 
        else {
            System.out.println("False");
            }
        }

   }
   catch(Exception e){
            JOptionPane.showMessageDialog(null, e);
  }

Codes below to search names and return result

   try
   {     
        string attendant = txtName.getText();

        ps = conn.prepareStatement(fill);
        rs = ps.executeQuery();

        int count = 0;

       while (rs.next()){
       String bName = rs.getString("name");

        if (attendant.equals(bName){
            System.out.println("True);
            break;
        } 
        else {
            System.out.println("False");
            }
        }

   }
   catch(Exception e){
            JOptionPane.showMessageDialog(null, e);
  }

I manged to get my 2nd code which is to search name and return result to work nicely. But as for the date search, it result false even I have the getDate() in SQL DB.

I did a System.out.println(x) and System.out.println(dDate) to verify the format but it turn out to be correct.

2013-01-17
2013-01-17

which should return “True”

Edited:

        java.util.Date now = new java.util.Date();
        java.sql.Date sqlDate = new java.sql.Date(now.getTime());

       I replace (x.equals(dDate)) to (sqlDate == dDate) but the result still return as false, any idea?

Please help..

Finally I got it..

Solution

       (Math.round(now.getTime() / 1000/3600/24) == Math.round(dDate.getTime() /1000/3600/24)
  • 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-17T08:51:01+00:00Added an answer on June 17, 2026 at 8:51 am

    Java Date contains time information also. Dates could differ in minutes or even seconds. To make sure both dates has exactly the same value you should print out date.getTime() which return long value of milliseconds since January 1, 1970, 00:00:00 GMT. If you wanna compare you should convert x from String to Date and then do this:

      x.getTime() == dDate.getTime()
    

    however, if you wanna compare just year, month and day you should trunk like this:

      Math.round(x.getTime()/1000/3600/24) == Math.round(dDate.getTime()/1000/3600/24)
    

    More about Date comparision in Java you can find here: Date Comparison using Java

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

Sidebar

Related Questions

I'm trying to convert timestamp (NSTimeInterval) to date format. I'm getting the correct current
Can anyone please share some java codes for getting started with google search api's.I
I have the following code for getting the last Sunday before the current date:
i want to generate current date and time in a format like this Mon,
I tried below snippet I'm getting current date and time of system instead of
I'm getting the current date/time using [NSDate date] . The value returned is an
I recently had help getting the correct Date format on my jQuery / tablesorter
This is code for get current date information is getting from database. It is
I'd like to have a helper class for getting the current date. I want
I have a website that displays the current date using the code Datetime.Now .

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.