Here you can find the source of getMonthAmount(java.sql.Date _startDate, java.sql.Date _endDate)
public static int getMonthAmount(java.sql.Date _startDate, java.sql.Date _endDate)
//package com.java2s; import java.util.Calendar; public class Main { public static int getMonthAmount(java.sql.Date _startDate, java.sql.Date _endDate) { int nYear = 0; int nMonth = 0; int nDay = 0; int nMonthAmount = 0; Calendar cldStart = Calendar.getInstance(); Calendar cldEnd = Calendar.getInstance(); cldStart.setTime(_startDate);//from ww w . j a v a 2 s.c om cldEnd.setTime(_endDate); nYear = cldEnd.get(Calendar.YEAR) - cldStart.get(Calendar.YEAR); nMonth = cldEnd.get(Calendar.MONTH) - cldStart.get(Calendar.MONTH); nDay = cldEnd.get(Calendar.DATE) - cldStart.get(Calendar.DATE); if (nDay > 14) { nMonthAmount = nYear * 12 + nMonth + 1; } else { nMonthAmount = nYear * 12 + nMonth; } return nMonthAmount; } }