I have a query which gets some Date type fields
The result of this query is downloaded to a .csv file and what it does is that it does NOT show the date fields in DD / MM / YYYY format, try to convert them with to_char
but when you show them in the excel they all come out with the same date and another year that nothing to see and when trying with to_date
the dates are correct but in another format, something like this Sat Jun 14 00:00:00 18
SELECT F.ID, F.NOMBRE, TO_DATE(F.FECHA_INI,'DD/MM/YYYY') FECHA_INI, TO_DATE(F.FECHA_REGISTRO,'DD/MM/YYYY') FECHA_REGISTRO, TO_DATE(F.FECHA.CARGA,'DD/MM/YYYY') FECHA CARGA, TO_CHAR(F.IMPORTE_UNO,'fm9990.00'), TO_CHAR(F.IMPORTE_DOS,'fm9990.00')
FROM FACTURA F
WHERE (?1 IS NULL OR F.ID =?1)
AND F.FECHA_INI >= TO_DATE(?2 'DD/MM/YYYY')
AND F.FECHA_INI <= TO_DATE(?3 'DD/MM/YYYY')
Why does that format come out and not the one I put in DD / MM / YYYY?
What makes me fata or is it wrong? It will be a question of how excel interprets the data?
I have the following code that I call from my controller to generate the .csv file
if(factList !=null) {
response.addHeader("Content-Type", "application/csv");
response.addHeader("Content-Disposition", "attachment;filename=archivo.csv");
PrintWriter out = response.getWriter();
out.write("ID,NOMBRE,FECHA_INI, FECHA_REGISTRO");
out.write("\n");
for(String factu: factList){
out.write(factu.toCSVRepresentation());
out.write("\n");
}
out.flush();
out.close();
}else{
log.info("Esta vacio");
}
}catch(ControlException e){ throw new ControlException("Error", e);
}
}