Ver Mensaje Individual
  #4 (permalink)  
Antiguo 31/01/2011, 09:55
Avatar de abimaelrc
abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 15 años
Puntos: 1517
Respuesta: cuantos sabados y cuantos domigos hay entre dos fecha en php

Trata algo así
Código PHP:
Ver original
  1. <?php
  2. function calcDays(){
  3.     $n = 0;
  4.     if(func_num_args() > 0){
  5.         foreach(func_get_args() as $value){
  6.             if(is_string($value) || (is_array($value) && count($value) == 1)){
  7.                 $value = is_string($value) ? $value : $value[0];
  8.                 $n += date('w', strtotime($value)) == 0 || date('w', strtotime($value)) == 6 ? 1 : 0;
  9.             }
  10.             elseif(is_array($value) && count($value) >= 2){
  11.                 $minNum = strtotime($value[0]) < strtotime($value[1]) ? $value[0] : $value[1];
  12.                 $maxNum = strtotime($value[0]) > strtotime($value[1]) ? $value[0] : $value[1];
  13.                 while(true){
  14.                     $addOne = empty($addOne) ? $minNum : date('Y-m-d', $addOne);
  15.                     $n += date('w', strtotime($addOne)) == 0 || date('w', strtotime($addOne)) == 6 ? 1 : 0;
  16.                     if(($addOne = strtotime('+1 day ' . $addOne)) > strtotime($maxNum)){ break;}
  17.                 }
  18.                 unset($addOne);
  19.             }
  20.         }
  21.     }
  22.     return $n;
  23. }
  24.  
  25. echo calcDays(array('2011-01-01', '2011-02-01')) . '<br />';
  26. echo calcDays(array('2011-01-01', '2011-02-01'), '2011-03-05', array('2011-03-06')) . '<br />';
  27. echo calcDays('2011-01-01', '2011-01-02', '2011-01-08') . '<br />';
__________________
Verifica antes de preguntar.
Los verdaderos amigos se hieren con la verdad, para no perderlos con la mentira. - Eugenio Maria de Hostos