Ver Mensaje Individual
  #5 (permalink)  
Antiguo 24/05/2010, 11:54
dfmex
 
Fecha de Ingreso: octubre-2008
Mensajes: 147
Antigüedad: 16 años, 4 meses
Puntos: 3
Respuesta: Ayuda con funcion de fechas por favor

Cita:
Iniciado por abimaelrc Ver Mensaje
Verifica si algo así es lo que quieres
Código PHP:
Ver original
  1. <?php
  2. $fecha = '2010-05-19';
  3. $now = strtotime($fecha);
  4. $n = 1;
  5. while($n <= 4){
  6.     $now = date('Y-m-d', $now);
  7.     echo $now . '<br />';
  8.     $now = strtotime('+1 day ' . $now);
  9.     if(date('N',$now) > 5){
  10.         $now = date('Y-m-d', $now);
  11.         $now = strtotime('+2 day ' . $now);
  12.         echo '<br />';
  13.         $n++;
  14.     }
  15. }

Muy interesante tu idea abimaelrc;

He realizado un pequeño cambio donde el dia inicial si no es lunes imprime LAST MONDAY, el problema es que si el dia de la fecha cae en sábado y domingo ya no imprime correctamente las 4 fechas....

Mira, te dejo el código que he modificado:

Código PHP:
<?php

$fecha 
'22-05-2010';
$now strtotime($fecha);
$n 1;
$lunes 1;
while(
$n <= 4){
    
$now date('d-m-Y'$now);
    
$diadate('l'strtotime($now));
    
    if(
$dia != 'Monday' && $lunes == 1){echo date('d-m-Y'strtotime('last monday'strtotime($fecha))).' - día: '.date('l'strtotime('last monday'strtotime($fecha))).'<br>'$lunes++;}
    if(
$dia == 'Monday' || $dia == 'Friday'){
    echo 
$now ' - día: '.$dia.'<br />'$lunes++;}
    
$now strtotime('+1 day ' $now);
    if(
date('N',$now) > 5){
        
$now date('d-m-Y'$now);
        
$now strtotime('+2 day ' $now);
        echo 
'<br />';
        
$n++;
    }
}

?>

Me agradó tu idea de usar el while condicionado a 4.

No sé si me puedas ayudar a verificar solo el detalle de que si la fecha indicada cae en sábado o domingo pues que imprima el siguiente lunes y viernes :$...


Gracias de antemano por tu ayuda.

Última edición por dfmex; 24/05/2010 a las 12:22