Ver Mensaje Individual
  #2 (permalink)  
Antiguo 23/10/2009, 07:09
quimfv
Colaborador
 
Fecha de Ingreso: marzo-2008
Ubicación: Sabadell
Mensajes: 4.897
Antigüedad: 16 años, 1 mes
Puntos: 574
Respuesta: Problema con manejo de fechas en un SELECT

Del manual de mysql...


Código sql:
Ver original
  1. SELECT titulo,visitas
  2.       FROM noticias
  3.       WHERE created BETWEEN
  4.                      DATE_SUB(NOW(),INTERVAL 5 DAY)
  5.                      AND NOW()
  6. ORDER BY visitas DESC LIMIT 10




Cita:
expr BETWEEN min AND max

If expr is greater than or equal to min and expr is less than or equal to max, BETWEEN returns 1, otherwise it returns 0. This is equivalent to the expression (min <= expr AND expr <= max) if all the arguments are of the same type. Otherwise type conversion takes place according to the rules described in Section 11.2.2, “Type Conversion in Expression Evaluation”, but applied to all the three arguments.
Primero el minimo y luego el maximo...

Pero esto quizas es mas simple no...

Código sql:
Ver original
  1. SELECT titulo,visitas
  2.       FROM noticias
  3.       WHERE created > DATE_SUB(NOW(),INTERVAL 5 DAY)
  4. ORDER BY visitas DESC LIMIT 10

Quim