+ 1

Calculate difference of 2 dates in java

How to calculate the difference between current date and a date from sql date? { Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/lmsdb?autoReconnect=true&useSSL=false","root","root"); Statement stt=conn.createStatement(); String SQuerry="SELECT RetrunDate FROM borrowedbooks WHERE MemberID='"+MemberID+"' AND BookID='"+BookID+"'"; ResultSet rss=stt.executeQuery(SQuerry); Date RetrunDate; while(rss.next()) { RetrunDate = new Date(rss.getDate("RetrunDate").getTime()); Date today=new Date(); Calendar myNextCalender=Calendar.getInstance(); myNextCalender.set(2021,0,1); //Here i need to add "RetrunDate, but it's not working" Date nextYearDate=myNextCalender.getTime(); long days=daysBetween(today,nextYearDate); SimpleDateFormat sdf=new SimpleDateFormat("MMM dd, YYYY"); String todaysdate=sdf.format(today); String newDate=sdf.format(nextYearDate); JOptionPane.showMessageDialog(this,days,"No of days",JOptionPane.INFORMATION_MESSAGE); } } private long daysBetween(Date one,Date two) { long differnce=(one.getTime()-two.getTime())/864000000; return Math.abs(differnce); } Have an issue when setting the "RetrunDate" into the calender format..

30th Mar 2018, 12:26 PM
Nishra Nasar
Nishra Nasar - avatar
3 Respuestas
+ 1
have u tried searching it online?! you can easily find ur answer by googling it.,. after that if u had problems implementing the code then ask about the problem of ur code here ..
30th Mar 2018, 1:33 PM
Farshaad Heydari
Farshaad Heydari - avatar
0
🙁🙁tried a lot. wait I'll upload my code.
30th Mar 2018, 1:46 PM
Nishra Nasar
Nishra Nasar - avatar
0
sorry...... I can't get my head around the code :( i hope u get the help that u want....
30th Mar 2018, 2:22 PM
Farshaad Heydari
Farshaad Heydari - avatar