How to Compare the Current Date and a given Date in a Jtable?
14,462
Use the code
DATEDIFF('d',NOW(),exdate)
in your resultset query. It will return the difference. Alter it possibly to match your needs.
Author by
zairahCS
Updated on June 15, 2022Comments
-
zairahCS about 2 years
Good Day. I've got another problem related to Jtable. I want to change the row color of a table if the date inside column (expiry) exceeds or is equal to the current date.
I tried this code but i get an error: java.lang.NumberFormatException: For input string: "2012-03-15"
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Calendar cal = Calendar.getInstance(); String expDateString = sdf.format(cal.getTime()); System.out.println(expDateString); Double date = Double.parseDouble(expDateString); Double val = Double.parseDouble(tableSummary.getModel().getValueAt(row, 6).toString()); for(int i=0; i<=tableSummary.getRowCount()-1; i++){ if(val >= date){ renderer.setBackground(red); } }
Thanks!
here's a new code:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Calendar cal = Calendar.getInstance(); String expDateString = sdf.format(cal.getTime()); Date today = new Date(expDateString); System.out.println("ang churva is " + today); Date given = new Date(tableSummary.getModel().getValueAt(row, 6).toString()); for(int i=0; i<=tableSummary.getRowCount()-1; i++){ if(today.compareTo(given)>=0){ renderer.setBackground(red); } }
but i get this exception: java.lang.IllegalArgumentException at Date today = new Date(expDateString);