Java SQL Date Month getMonthAmount(java.sql.Date _startDate, java.sql.Date _endDate)

Here you can find the source of getMonthAmount(java.sql.Date _startDate, java.sql.Date _endDate)

Description

get Month Amount

License

Open Source License

Declaration

public static int getMonthAmount(java.sql.Date _startDate, java.sql.Date _endDate) 

Method Source Code

//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;
    }
}

Related

  1. getFirstDayOfNextMonth(Date date, boolean isFormatDate)
  2. getMinDayInMonth(java.sql.Date date)
  3. getMonth(Date date)
  4. getMonth(final java.sql.Date date)
  5. getMonthBefroe(Date date)
  6. getMonthDate(Date myDate, int month)
  7. getMonthDays(java.sql.Date date)
  8. getMonthFromYMD(Date ymd)