Ver Mensaje Individual
  #7 (permalink)  
Antiguo 16/11/2011, 11:47
ivan_xunxoow
 
Fecha de Ingreso: noviembre-2011
Mensajes: 11
Antigüedad: 13 años, 4 meses
Puntos: 0
Respuesta: comparar fechas con base de datos en php???

Cita:
Iniciado por johhan16 Ver Mensaje
Yo tengo algo parecido a lo que necesitas, pero de nada vale entregártelo todo si no vas a aprender.

pero vuelvo y te coloco el ejemplo un poco mejor para que lo pruebes

Código PHP:
Ver original
  1. <?php
  2. $i= 0;
  3. $dia = 0;
  4.  
  5. $fecha_ini = '2011-11-16';
  6. $fecha_fin = '2011-11-26';
  7.  
  8. $fecha2 = strtotime($fecha_fin);
  9.  
  10.  
  11. while ($fecha2 > $dia) {
  12.  
  13. $dia = strtotime('+'.$i.' day', strtotime($fecha_ini));
  14.  
  15. $i++;
  16.  
  17. }
  18.  
  19. echo "Desde la Fecha: " .$fecha_ini." Hasta la Fecha: ".$fecha_fin." Hay: ".$i." Dias";
  20. ?>
mira sii me resulto pero aun no lo k io kiero .... mira sii me compara bn pero me sale asi

2011-10-17
2011-10-17
2011-10-17
2011-10-13
2011-10-13
2011-10-13
2011-10-13
2011-10-13
2011-10-13
2011-10-25
2011-10-25
2011-10-25
2011-10-25
2011-10-25
2011-10-25
2011-10-25
2011-10-25
2011-10-25
2011-10-25
2011-11-10
2011-11-10
2011-11-10
2011-11-10
2011-11-10

y yo kiero k sean consecutivos y obviamente reemplaze las fechas k pusiste por las fechas k extraje desde la base de datos mira te dejo el codigo y me dices k falta o k falla

Código PHP:
<?php
$fecha_ini
=$_POST['fecha'];
  
$fch=explode("/",$fecha_ini);
  
$fecha_ini=$fch[2]."-".$fch[1]."-".$fch[0];


  
$fecha_ter=$_POST['fecha1'];
  
$fch1=explode("/",$fecha_ter);
  
$fecha_ter=$fch1[2]."-".$fch1[1]."-".$fch1[0];

   
$conexion=mysql_connect("localhost","root","") or die("Problemas en la conexion");
   
mysql_select_db("recursos_humanos",$conexion) or die("Problemas en la seleccion de la base de datos");
  
  
$query="SELECT * FROM movimientos INNER JOIN personal ON movimientos.RUT_EMPLE = personal.RUT_EMPLE WHERE movimientos.FECH_INI BETWEEN '$fecha_ini' AND '$fecha_ter'";
$result=mysql_query($query,$conexion) or die("Error: ".mysql_error());
if(
mysql_num_rows($result) > 0){
while(
$Rs=mysql_fetch_array($result)){
$i0;
$dia 0;
$fech_pas $Rs["FECH_INI"];
$fech_fin $Rs["FECH_FIN"];
$fecha2 strtotime($fech_fin);
while (
$fecha2 $dia) {
$dia strtotime('+'.$i.' day'strtotime($fech_pas));
if(
$fecha_ini <= $fech_pas && $fech_pas <= $fecha_ter){
echo 
$fech_pas."<br>";
}
$i++;
}


}
}
mysql_close($conexion); 
?>
gracias y disculpa tantas molestias