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 6804521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:28:34+00:00 2026-05-26T19:28:34+00:00

I am trying to get two dates from a SQL query, and compare them.

  • 0

I am trying to get two dates from a SQL query, and compare them. So to compare them, I believe I will need to use the “Date” type. Here is what I am trying, I know I am getting the date from the resultSet incorrectly, but I am not sure how to do it.

Date validDate = new Date(0);
Date currentDate = new Date(0);

// query

    if (result.next()) {

    validDate  = (result.getObject("validDate")!=null)?result.getObject("validDate").toDate():"";
    currentDate = (result.getObject("currentDate")!=null)?result.getObject("currentDate").toDate():"";
}

if (currentDate > validDate) {
    //do something
}

So again, this was my attempt, but I cant seem to get it to run. Thanks in advance.

EDIT: the query has TO_CHAR(column, ‘MM-DD-YYYY’) on the two dates that I am getting.

  • 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-05-26T19:28:35+00:00Added an answer on May 26, 2026 at 7:28 pm

    EDIT: Now you’ve mentioned that your query converts the date to a string, stop doing that. You’ll end up reparsing it on the calling side – so why perform two conversions pointlessly? Keep string conversions to the absolute minimum – stay in the most appropriate data type wherever possible.


    Original answer

    You haven’t shown what result is, but you probably want something like ResultSet.getDate() to fetch the date values.

    Note that your comparison code won’t work either because there’s no > for Date – you’d need something like:

    if (currentDate.after(validDate))
    

    Or fetch the underlying number of millis:

    if (currentDate.getTime() > validDate.getTime())
    

    Additionally:

    • You can’t assign “” to a Date variable – a string isn’t a Date.
    • You can just call ResultSet.getDate() and check whether the returned value is null, rather than calling getObject first and then getDate()
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get the dates from entries in two different RSS feeds through
I'm trying to get the AVERAGE from the results of two separate sql queries
I am trying to fetch records based on two dates from sql server... Select
I need to get two fields from a database table (retrieved using linq-to-sql), one
I'm trying to compare two datetimes but I can't get it to work. public
I am having an SQL query problem. I am trying to get data in
I have the following SQL Server query and I am trying to get the
I am having a problem when i am trying to compare two dates in
Trying to pull fields 'info' and 'date' from Comment table. Two Tables: Php <?php
In my GWT project, I'm trying to get it so two DialogBoxes can pass

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.