Ver Mensaje Individual
  #3 (permalink)  
Antiguo 29/03/2011, 09:19
monxas
 
Fecha de Ingreso: mayo-2009
Mensajes: 201
Antigüedad: 15 años
Puntos: 9
Respuesta: Como saber cuantas quincenas existen

Prueba esto:
Código PHP:
Ver original
  1. floor(($fecha2 - $fecha1) / 1296000)+1
(Las fechas tienen que estar en segundos, con strtotime() )
Eso debería servir.
Comprueba que esté bien (no toy seguro, apenas lo probe) con esto:
Código PHP:
Ver original
  1. <?
  2.  
  3.  
  4. if (isset($_POST['fecha1'])) {
  5.     $posted=true;
  6.     $fecha1 = strtotime($_POST['fecha1']);
  7.     $fecha2 = strtotime($_POST['fecha2']);
  8.     }else{$posted=false;}
  9. ?>
  10. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  11. <html xmlns="http://www.w3.org/1999/xhtml">
  12. <head>
  13. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  14. <title>Documento sin título</title>
  15. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
  16. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/jquery-ui.min.js"></script>
  17. <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/ui-lightness/jquery-ui.css" type="text/css" media="all" />
  18.  
  19. <script>
  20.     $(document).ready(function() {
  21.        
  22.        $('#fecha1').datepicker();
  23.        $('#fecha2').datepicker();
  24.        
  25.     });
  26. </script>
  27.  
  28. </head>
  29.  
  30. <body>
  31.  
  32. <form action="restafechas.php" method="post">
  33. <input name="fecha1" id="fecha1" type="text" />
  34. <input name="fecha2" id="fecha2" type="text" />
  35. <input name="Enviar" type="submit" />
  36. </form>
  37.  
  38. <?
  39.  
  40.  
  41. if ($posted) {
  42. echo date('l jS \of F Y h:i:s A',$fecha1)."<br />";
  43. echo date('l jS \of F Y h:i:s A',$fecha2)."<br />";
  44. echo floor(($fecha2 - $fecha1) / 1296000)+1 . "<br />";
  45.  
  46.  
  47.     }
  48. ?>
  49.  
  50. </body>
  51. </html>

Para que funcione llama al archivo restafechas.php