2

Possible Duplicate:
How to calculate the difference between two Java java.sql.Timestamps?

How do you calculate how many years/months/days (don't really need time) between two timestamps that you've acquired from an SQL in Java?

Below is a snippet of a code I'm using:

query = "SELECT bc.periodbeginningdate " +
            "FROM cus_billingcontract bc " +
            "WHERE cus_billingcontract_id = " + recordID;
Timestamp bDate = DB.getSQLValueTS(null, query);

query = "SELECT bc.periodenddate " +
            "FROM cus_billingcontract bc " +
            "WHERE cus_billingcontract_id = " + recordID;
Timestamp eDate = DB.getSQLValueTS(null, query);
Community
  • 1
  • 1
user1353252
  • 39
  • 1
  • 6

1 Answers1

1

You can convert the timetamps to longs by using getTime(): see here for lots of info:

How to calculate the difference between two Java java.sql.Timestamps?

Then, with the long values, you can use the JodaTime libraries to easily access months differences.

See here:

How to calculate difference ONLY in months using Java's Joda API

Community
  • 1
  • 1
davek
  • 22,499
  • 9
  • 75
  • 95