| Author |
Date differences in months...
|
George Larry
Ranch Hand
Joined: Nov 07, 2001
Posts: 52
|
|
Question: How can I get the number of months between 2 dates? ie. I want to find out how many months are between the following dates: Aug 5, 01 - Aug 7, 01 : # of months = 1 Aug 28, 01 - Oct 2, 01 : # of months = 3 (Aug, Sept, Oct) Aug 19, 00 - Aug 3, 01 : # of months = 13 I get the dates in string format, but convert them to java.sql.Dates using the code below: uDate = ( java.util.Date )fDate.parse( fromDate, pos1 ); rSqlFromDate = new java.sql.Date(uDate.getTime()); uDate = ( java.util.Date )fDate.parse( toDate, pos2 ); rSqlToDate = new java.sql.Date(uDate.getTime()); ...once I have them converted to sql.Dates I am able to use them in my queries, but I need to find out how many months are covered. I've never done this before... any help would be appreciated. Thanks.
|
 |
Bosun Bello
Ranch Hand
Joined: Nov 06, 2000
Posts: 1506
|
|
You will need something like the java.util.Calendar class. Check the API for it's various methods. Bosun ------------------ Bosun SCJP for the Java� 2 Platform
|
Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
|
 |
 |
|
|
subject: Date differences in months...
|
|
|