2011-03-27 23 views

Respuesta

12
$now = time(); 
$beginning_of_week = strtotime('last Monday', $now); // Gives you the time at the BEGINNING of the week 
$end_of_week = strtotime('next Sunday', $now) + 86400; // Gives you the time at the END of the last day of the week 
+3

pero ¿Qué hacer cuando hoy es lunes? Tengo la semana de 14 días. – Molfar

+4

A continuación, compruebe si hoy es lunes y si lo reemplaza el "último lunes" con "hoy". Para ver si actualmente es lunes, haga 'if (date ('w', $ now()) == 1)' – jackbot

+0

Parece, también debe agregarse "UTC" para obtener UTC0 timeStamp – 4esn0k

2
public static function getDaysInWeek($timestamp) 
{  
    $monday = idate('w', $timestamp) == 1 ? $timestamp : strtotime("last Monday", $timestamp); 

    $days = array(); 
    for ($i = 0; $i < 7; ++$i) 
    { 
     $days[$i] = strtotime('+' . $i . ' days', $monday); 
    } 
    return $days; 
} 
5
if (date('w', time()) == 1) 
    $beginning_of_week = strtotime('Today',time()); 
else 
    $beginning_of_week = strtotime('last Monday',time()); 

if (date('w', time()) == 7) 
    $end_of_week = strtotime('Today', time()) + 86400; 
else 
    $end_of_week = strtotime('next Sunday', time()) + 86400; 
Cuestiones relacionadas