DB Date is 11-18-2011 03:40:56 and current date is in the same format.
How to compare? I have implemented the following but it is not giving correct result.
Below is my code.
Calendar calendar = Calendar.getInstance();
Calendar currentDate = Calendar.getInstance();
SimpleDateFormat formatter= new SimpleDateFormat("MM-dd-yyyy HH:mm:ss");
String dateNow = formatter.format(currentDate.getTime());
if(datenow.toString.equals(date2)){
}
You should not compare the string representation of dates but use the actual object.
If
date2is ajava.sql.Dateorjava.util.Dateyou can compare them as is, usingnew Date().equals(date2).Just be aware that dates are stored in millisecond precision so you might want to remove the fields you don’t want before comparing, or use Apache Commons’
DateUtils, e.g.DateUtils.isSameDay(date2, new Date());