I have 2 JDateChooser, when I do JDateChooser1.getDate returns the selected date with time 00:00:00
When I do JDateChooser2.getDate, it returns the selected date with the time when the selection was made.
I need both JDateChooser to return the hour 00:00:00
.
Annex code, never enters else
of if
, because the dates are never equal for the difference of hours when making the choice of date.
public void llenaCalendarioTarifas(){
String consulta = "Insert into calendario tarifas (fecha, id_tarifa, id_tipoCuarto) values ";
String fecha = new SimpleDateFormat("yyyy-MM-dd").format(dateInicio.getDate());
String fechaF = new SimpleDateFormat("yyyy-MM-dd").format(dateFinal.getDate());
String idTarifa ="5";
Date fInicio = dateInicio.getDate();
Date fFinal = dateFinal.getDate();
Calendar cal= Calendar.getInstance();
while(fInicio.compareTo(fFinal)<= 0){
if(fInicio.compareTo(fFinal)== -1){
consulta = consulta + "\n('" + fecha + "', " + idTarifa + ", " + idTipo + "), ";
// JOptionPane.showMessageDialog(null, consulta);
}else {
consulta = consulta + "\n('" + fecha + "', " + idTarifa + ", " + idTipo + ")";
// JOptionPane.showMessageDialog(null, consulta);
}
cal.setTime(fInicio);
cal.add(Calendar.DATE, 1);
fInicio = cal.getTime();
fecha = new SimpleDateFormat("yyyy-MM-dd").format(fInicio);
}
JOptionPane.showMessageDialog(null, consulta);
}