java date


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/
gdv82Asked:
Who is Participating?
 
CEHJCommented:
Set the Calendar a day forward

cal.setTime(dateEntered);
cal.add(Calendar.DATE, 1);
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> 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.
0
 
CEHJCommented:
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);
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
gdv82Author Commented:

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"

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

use sql 'between' in your query
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Post your entire code for query-building.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.