java date

Posted on 2006-04-27
Last Modified: 2010-03-31

i am getting date string from the gui. i have a query like:

if argument is after and date is 04/05/2006 what it is returning is like all the data after this specified date
 but actually it should return data when > = (date+1)

i dont want any data for 04/05/2006 since my argument is after..

i m stuck with all date arithmetics.

please help/
Question by:gdv82
    LVL 86

    Accepted Solution

    Set the Calendar a day forward

    cal.add(Calendar.DATE, 1);
    LVL 30

    Assisted Solution

    >> but actually it should return data when > = (date+1)

    Then you need to define the upper limit of the query (I assume its a DB query). It should have less than whatever is the date till which you want to see results.
    LVL 86

    Expert Comment

    Once you've followed what i suggested, if you're querying a db

    java.sql.Date lower = new java.sql.Date(cal.getTimeInMillis());
    java.sql.Date upper = new java.sql.Date(System.getTimeMillis()); // (IOW - now)

    preparedStatement.setDate(i, lower);
    preparedStatement.setDate(j, upper);

    Author Comment


    hi thx for the comments but what actually i m doing is like i m generating sqlquery based of the input using java beans. my gui and java code is separate.

                 query.append(dateString + " to_date('" + date + "', 'mm/dd/yyyy') ");

    here date is a string
    if date is "05/04/2006" and argument is after then

    i need data where date >= "05/05/2006"

    LVL 86

    Expert Comment

    You don't need to call to_date (see the code i posted)

    use sql 'between' in your query
    LVL 30

    Expert Comment

    Post your entire code for query-building.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    If you have upgraded to Java2 update 10 on a Microsoft Windows client, you may have discovered that your Java application does not work as it did before.  For example, the colors of your Java2D graphic may be all wrong for no apparent reason. Aft…
    For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
    Video by: Michael
    Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
    Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now