public long differencedate(object sdate ,object edate) throws exception{ java.util.date date1 = null; java.util.date date2 = null; if(sdate == null){ throw new exception("start date should not be null"); } if(edate == null){ throw new exception("end date should not be null"); } if((sdate instanceof java.util.date) || (sdate instanceof java.sql.date)){ date1 = (java.util.date)sdate; } else{ throw new exception("end date should be util date or sql date"); } if((edate instanceof java.sql.date) || (edate instanceof java.util.date)){ date2 = (java.util.date)edate; } else{ throw new exception("end date should be util date or sql date"); } long diff=date1.gettime()-date2.gettime(); long days=(diff / (1000 * 60 * 60 * 24)); if(days < 0){ throw new exception("start date should be greater than end date"); } return days; }