File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes finding difference b/n two dates in hours Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "finding difference b/n two dates in hours" Watch "finding difference b/n two dates in hours" New topic

finding difference b/n two dates in hours

Srikrishna DhumalRao

Joined: Oct 05, 2004
Posts: 17
I have two datetime formats rpt_dt_time and cur_dt_time , I want to find the difference between these dates in hours and check wether it has crossed the estimated time and act accordingly.I am working on Oracle DB and Windows 2000 OS

Henrique Sousa
Ranch Hand

Joined: Apr 29, 2004
Posts: 92
I don't think it would be appropriate to just give you the solution (which would be quite an amount of code), but there are a few subjects you must know in order to implement the solution:

- JDBC: Read the API and Java Tutorial on the subject. You will need it to connect and execute your queries to the Oracle DB (you will need the Oracle JDBC driver)
- Check out the java.util.Date, java.sql.Date, java.sql.Timestamp and java.util.Calendar classes, you will surely need some of them.

Then write some code and if you fail to achieve the answer to your problem we will gladly help you. Regards,

Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

After looking at the Java Tutorial and API documentation, you can also take a look at these articles at
  • Calculating Java dates
  • Working in Java time: Learn the basics of calculating elapsed time in Java
  • Joe Vocioni

    Joined: Sep 28, 2004
    Posts: 3
    If I may make a suggestion. I ran into a similar problem with an application that we were developing. The solution we chose was to calculate the difference in milliseconds.

    The reson we selected this route is if we had a scenario like;
    12-31-2002 23:59:59 and 01-01-2003 00:00:01
    -- The real time difference is only 2 seconds.

    So using the hour approach would have been inadequate in our situation.
    Srikrishna DhumalRao

    Joined: Oct 05, 2004
    Posts: 17
    Thanks for the reply . I am able to make up the solution
    I agree. Here's the link:
    subject: finding difference b/n two dates in hours
    It's not a secret anymore!