Cita:
Iniciado por abimaelrc
Verifica si algo así es lo que quieres
Código PHP:
Ver original<?php
$fecha = '2010-05-19';
$n = 1;
while($n <= 4){
$now = date('Y-m-d', $now); echo $now . '<br />';
$now = date('Y-m-d', $now); echo '<br />';
$n++;
}
}
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);
$dia= date('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.