Ver Mensaje Individual
  #2 (permalink)  
Antiguo 14/03/2014, 21:31
Avatar de farfamorA
farfamorA
 
Fecha de Ingreso: noviembre-2010
Ubicación: Lima
Mensajes: 136
Antigüedad: 13 años, 5 meses
Puntos: 24
Respuesta: como obtener fechas entre un intervalo dado

Almacena las fechas en una lista, con eso evitas la concatenación.
Código Java:
Ver original
  1. public List<Date> getListaEntreFechas(Date fechaInicio, Date fechaFin) {
  2.     Calendar c1 = Calendar.getInstance();
  3.     c1.setTime(fechaInicio);
  4.     Calendar c2 = Calendar.getInstance();
  5.     c2.setTime(fechaFin);
  6.     List<Date> listaFechas = new ArrayList<Date>();
  7.     while (!c1.after(c2)) {
  8.         listaFechas.add(c1.getTime());
  9.         c1.add(Calendar.DAY_OF_MONTH, 1);
  10.     }
  11.     return listaFechas;
  12. }
Y luego la recorres fácilmente:
Código Java:
Ver original
  1. for (Iterator<Date> it = listaEntreFechas.iterator(); it.hasNext();) {
  2.     Date date = it.next();
  3.     // Lógica de negocio
  4. }