Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I am using this method to validate the date is in 5 years range it is working fine if I add begin date as 2011-01-01 and end date as 2015-12-30 and getting some data from database but when I change my end date to 2015-12-31 (which is a valid 5 years range according to my professor) it is giving me "DATE_RANGE_EXCEEDED must be less than 5 years" because it is adding one year as leap year.....


public class DateValidation {
final int CONST_YEAR_RANGE = 5;
final Calendar searchBeginDate = input.getBeginDate();
final Calendar searchEndDate = input.getEndDate();


                final int endYrDos  = searchEndDate.get(Calendar.YEAR);
                final int startYrDos = searchBeginDate.get(Calendar.YEAR);

                if (endYrDos - startYrDos > CONST_YEAR_RANGE) {

System.out.println("DATE_RANGE_EXCEEDED must be less than 5 years", + endYrDos, startYrDos);
    }



Please help.....

Thanks
Posted
Comments
Sandeep Mewara 24-Oct-12 11:01am    
I believe logic is to get data for last 5 years from now. If so, use current data and 5 years back date (let Java handle the leap year and give you correct back date). Implement your logic around it.
rbjanaki 24-Oct-12 11:35am    
Hi Sandeep,

Thanks for quick reply, do you have any examples how to do this logic......

Sandeep Mewara 24-Oct-12 11:40am    
Is that not straight forward? :confused:

date1 = current date
date2 = current date - 5 years

Use logic with date1 & date 2 with days difference instead of just year.

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900