Posted By

takel on 03/04/11


Tagged

dates week


Versions (?)

week dates


 / Published in: PHP
 

  1. function week_dates($date = null, $format = null, $start = 'monday') {
  2. // is date given? if not, use current time...
  3. if(is_null($date)) $date = 'now';
  4.  
  5. // get the timestamp of the day that started $date's week...
  6. $weekstart = strtotime('last '.$start, strtotime($date));
  7.  
  8. // add 86400 to the timestamp for each day that follows it...
  9. for($i = 0; $i < 7; $i++) {
  10. $day = $weekstart + (86400 * $i);
  11. if(is_null($format)) $dates[$i] = $day;
  12. else $dates[$i] = date($format, $day);
  13. }
  14.  
  15. return $dates;
  16. }

Report this snippet  

You need to login to post a comment.