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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:30:24+00:00 2026-05-30T13:30:24+00:00

I have a database field where date is stored as DD/MM/YYYY format. Now what

  • 0

I have a database field where date is stored as DD/MM/YYYY format. Now what I want to do is to see if today date = stored date – 1. Basically if today is the day before the end date. Based on that I will do some action…

example of format:

10/02/2012

There is formatting issue here because am using this:

Date todayDate;

And the stored date is VARCHAR2 in DB. Am assuming I would have to convert the retrieved date to Date regular format, or something like that. Help would be appreciated.

Update:

                currentEndDate =  rset.getString("ENDDATE");
                endDate = (Date)formatter.parse(currentEndDate);
                /*Check if end date = today date - 1*/
                Calendar cal = Calendar.getInstance();
                //set to end date
                cal.setTime(endDate);
                //end date - 1
                cal.add(Calendar.DATE, -1); 
                Date today;

Now this is what I have..I am trying here to get the end date -1 so I did that using add() function. Now How can I check if end-date – 1 == today date or not? because when I tried :

if(today.equals(cal.add(Calendar.date, -1)))

it said void return from the add function.
Thanks,

  • 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-30T13:30:25+00:00Added an answer on May 30, 2026 at 1:30 pm

    You need to turn the String into a date. You can do this in your query or after you get the string result:

    Option 1: turn it into a Date type in your query:

    SELECT TO_DATE("COLNAME", 'MM/DD/YYYY') FROM "MYTABLE"
    

    Option 2: turn it into a Date type after you get the string:

    String date_from_db;
    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
    Date date = sdf.parse(date_from_db);
    

    Then you can see if the current time (new Date()) is between the retrieved date and a day before that. If you want to handle all corner cases including leap seconds, you’ll have to use a Calendar, but if you’re okay with leaving out leap seconds then it’ll be fine to just subtract 24*60*60*1000 milliseconds from your db date.

    You can’t directly compare a Date and a Calendar as per the API documentation:

    …objects are equal if and only if the getTime method returns the same long value for both

    Also, Calendar‘s equals() won’t work:

    The result is true if and only if the argument is a Calendar object of the same calendar system that represents the same time value

    Simple solution: use the Calendar‘s getTime() method, which returns a Date object which will readily compare with other dates using equals(), after(), and before().

    Or in code:

    cal.add(Calendar.DAY, -1);
    if(cal.getTime().equals(new Date())) { ... }
    

    You could also instantiate another Calendar and use its setTime(), but that seems less efficient.

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

Sidebar

Related Questions

i want to compare database field of date that has YYYY-MM-DD format and i
I have Database with date field. I see the time like: 1900-01-01 13:38:00.000 How
I have date in dd/mm/yyyy format. How can I store it in a database,
I have a database with a field for a stored date. I would like
I have a huge database (800MB) which consists of a field called 'Date Last
I have a database field called abCode , that I want to map to
I have a database field where I want to store my password. In a
I have a MySQL database with a date_of_birth field. The data stored in this
In my database I have a field date of type varchar where the date
I have a birthdate field stored in a table in the database.At present it

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.