i need to calculate months between two dates, if the startDate=2013.01.01, endDate=2013.01.31 the answer should be 1, startDate=2013.01.01, endDate=2013.02.01 the answer should be 2. please help
Asked
Active
Viewed 1.4k times
2
-
i just want to do a calculation by getting the months. i wants to get the number of months.if the start date=january 1st and the end date=feb 1st there have the january and febrary like wise i wants to know how many months are there in between that two dates – user2717410 Aug 26 '13 at 08:53
1 Answers
8
Use Joda Months:
DateTime start = new DateTime(startDate.getTime());
DateTime end= new DateTime(endDate.getTime());
int months = Months.monthBetween(start, end).getMonths();

Jean Logeart
- 52,687
- 11
- 83
- 118