?
Solved

java date

Posted on 2006-04-27
10
Medium Priority
?
174 Views
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/
0
Comment
Question by:gdv82
  • 3
  • 2
6 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 1000 total points
ID: 16552582
Set the Calendar a day forward

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

Assisted Solution

by:Mayank S
Mayank S earned 1000 total points
ID: 16552851
>> 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
 
LVL 86

Expert Comment

by:CEHJ
ID: 16552933
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:gdv82
ID: 16553335

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
 
LVL 86

Expert Comment

by:CEHJ
ID: 16553845
You don't need to call to_date (see the code i posted)

use sql 'between' in your query
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16554090
Post your entire code for query-building.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month17 days, 8 hours left to enroll

831 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