• Post Reply Bookmark Topic Watch Topic
  • New Topic

java- find days between two days.  RSS feed

 
isha malee
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want this method to happen at the application load.where i should call this method?

and i want to find days between systemdate and nextdate.. how can i do it..
and want to update no of arrears days column in the whole table.how can i do this too.??
please help.uncompleted code is below.


try {
Connection c = MyDB.getCon();
Statement stmt = c.createStatement();
qry = "select agencyCode,fundCode,nextDate from fundagency ";
rs = stmt.executeQuery(qry);
Date nxtdate, systemdate = new Date();
if (rs.next()) {
nxtdate = df.parse(rs.getString("nextDate"));
cal2.setTime(nxtdate);

//substract 2days and update the column "arrears days" of the table, noOfArrearsDays=systemDate-nxtDate


} else {

}
stmt.close();
c.close();


} catch (Exception e) {
e.printStackTrace();
}
 
M Massa
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could call this method in the init() method of your servlet. You can also look into implementing ServletContextListener and calling it in the contextInitialized(ServletContextEvent) method.

If you are trying to subtract 2 days from the date as your comment line says, look into the add() method of the Calendar class:

To get the difference between any dates, get the time in milliseconds and divide until you get to the unit you want.
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use Calendar, much more modern with a ton or arithmetic features.

WP
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
isha malee
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for the replies.. i solved it out with your help...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!