• Post Reply Bookmark Topic Watch Topic
  • New Topic

Date differences in months...  RSS feed

 
George Larry
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1512
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!