Difference in days

I have two Date parameters from DB2 database, as Startdate and Enddate, In query string i am calling them as,

java.sql.Date hi = rs.getDate("STARTDATE");
java.sql.Date hi1 = rs.getDate("ENDDATE");

How do i find the difference in number of days in integer between these two dates?

I have tried out many ways, but none seems to work, the milliseconds thing isnt working as well. Only the gregorian calendar thing worked under given date, but then how do i add Startdate and Enddate to a Gregoriancalendar?

Calendar then = new GregorianCalendar(2008, Calendar.OCTOBER, 27);
Calendar now = new GregorianCalendar();

Like say for how do i add the date there instead of the predefined date?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

First set the start Calendar


then add days until


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial

Until hi1.after(cal1.getTime()) == false;
kingsofjupiterAuthor Commented:
Just like many other method this also does not shows any error but it is not showing the output, I am putting up the code here, Any idea where the thing is going wrong?

	    while (rs.next())
	     java.sql.Date hi = rs.getDate("STARTDATE");
	     java.sql.Date hi1 = rs.getDate("ENDDATE");
	     int diff = 0;
	     //Calendar then = Calendar.getInstance();    
	     Calendar then = new GregorianCalendar();
	     boolean b = hi1.after(then.getTime());
		} catch(Exception e) { System.out.println(e); }

Open in new window

Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

kingsofjupiterAuthor Commented:
It seems the whole while loop is executing only once, the inner while loop i mean, I am trying out some other options using the same code, also it seems if the database has date value as NULL which it will have incase of unoccupied Wards, the query loop is exiting straightaway after finding a single null.
>>the inner while loop i mean

There isn't one - that's the problem
kingsofjupiterAuthor Commented:
Thanks a lot, I fixed the problem, output now is coming perfectly, and when it is null, it is not even showing the output for the record corresponding the null value, so thats good as well.

Thanks a lot.
Good ;-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.