Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>this works perfect!!! phpfiddle <a href="http://phpfiddle.org/main/code/0zy-7nh" rel="nofollow">here</a></p> <pre><code>&lt;?php // start and end must be timestamps !!!! $start = 1346976000; // Thu 2012-09-06 $end = 1348704000; // Tue 2012-09-26 // generate the weeks $weeks = generateweeks($start, $end); // diaplay the weeks echo 'From: '.fDate($start).'&lt;br&gt;'; foreach ($weeks as $week){ echo fDate($week['start']).' '.fDate($week['end']).'&lt;br&gt;'; } echo 'To: '.fDate($end).'&lt;br&gt;'; /* outputs this: From: Thu 2012-09-06 Thu 2012-09-06 Sun 2012-09-09 Mon 2012-09-10 Sun 2012-09-16 Mon 2012-09-17 Sun 2012-09-23 Mon 2012-09-24 Wed 2012-09-26 To: Wed 2012-09-26 */ // $start and $end must be unix timestamps (any range) // returns an array of arrays with 'start' and 'end' elements set // for each week (or part of week) for the given interval // return values are also in timestamps function generateweeks($start,$end){ $ret = array(); $start = E2D($start); $end = E2D($end); $ns = nextSunday($start); while(true){ if($ns&gt;=$end) {insert($ret,$start,$end);return $ret;} insert($ret,$start,$ns); $start = $ns +1; $ns+=7; } } // helper function to append the array and convert back to unix timestamp function insert(&amp;$arr, $start, $end){$arr[] = array('start'=&gt;D2E($start), 'end'=&gt;D2E($end));} // recives any date on CD format returns next Sunday on CD format function nextSunday($Cdate){return $Cdate + 6 - $Cdate % 7;} // recives any date on CD format returns previous Monday on CD format // finaly not used here function prevMonday($Cdate){return $Cdate - $Cdate % 7;} // recives timestamp returns CD function E2D($what){return floor($what/86400)+2;} // floor may be optional in some circunstances // recives CD returns timestamp function D2E($what){return ($what-2)*86400;} // 24*60*60 // just format the timestamp for output, you can adapt it to your needs function fDate($what){return date('D Y-m-d',$what);} </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload