Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within JDBC and Relational Databases
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Ron McLeod
Jeanne Boyarsky
Sheriffs:
Paul Clapham
Saloon Keepers:
Tim Holloway
Roland Mueller
Bartenders:
Forum:
JDBC and Relational Databases
Difference between two timestamp fields
JayaSiji Gopal
Ranch Hand
Posts: 303
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I have two fields DECISION_DATE and EVENT_DATE
Both are of type Timestamp in the database(DB2 v8)
i want to check if the diff between the two dates is 1.
I tried days(DECISION_DATE) - days(EVENT_DATE) = 1 .
I get the exception: days() is not a valid function.
What would be the best way?
SCJP 1.4, SCWCD 1.4<br /> <br />Thanks in advance!<br />Jayashree.
Qussay Najjar
Ranch Hand
Posts: 53
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi JayaSiji,
Honestly I don't know the solution for this using
Java
methods,
I've faced this problem before, but as I'm using Oracle DB I used a query as the next:
public boolean isDifferentOne(Connection connection, Timestamp decisionDate , Timestamp eventDate){ if(decisionDate==null || eventDate==null) return false; Statement statement = null; ResultSet rs = null; String query = "SELECT To_Date('"+eventDate.toString()+"','YYYY-MM-DD HH24:MI:SS')-To_Date('"+decisionDate.toString()+"','YYYY-MM-DD HH24:MI:SS') FROM DUAL"; int subtractResult=0; try{ statement = connection.createStatement(); rs = statement.executeQuery(query); if(rs.next()) try{subtractResult = rs.getInt(1);}catch(NullPointerException npe){subtractResult=0;} rs.close(); statement.close(); if(subtractResult==1) return true; }catch(SQLException e){ return false; } return false; }
This is how I solved my problem that day, hope it helps or gives a clue..
Qussay NAJJAR
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
hibernate usage--sql syntax error
Handling java.sql.Timestamp
Timestamp not updating in mysql
doubt regarding jdbc syntax error while creating a table
Repeated updates on EVENT table, in Hibernate one to many mapping
More...