note 60812 deleted from function.date by derick

From: Date: Sun, 11 Jun 2006 11:42:17 +0000
Subject: note 60812 deleted from function.date by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-114245@lists.php.net to get a copy of this message
Note Submitter: infolock at gmail dot com ---- I have revised this one final time. Sorry for the first post which will now clutter. Anyways, here is the revised edition. This function will allow you to display the results as below, or you can also group by month. This allows the weeks to be nicely seperated for each month. <?php function get_weeks($year, $group_by_month = false) { $firstday_ts = mktime(1,0,0,1,1,$year); $firstday = date("w", $firstday_ts); if($group_by_month === false) { $weeks[] = date('Y-m-d',$firstday_ts); } else { $m = 'Jan'; //start month $weeks[$m][] = date('Y-m-d',$firstday_ts); } $first = $firstday_ts; if($firstday > 0) { $x = 8 - $firstday; $first = mktime(1,0,0,1,$x,$year); if($group_by_month === false) { $weeks[] = date('Y-m-d',$first); } else { $weeks[$m][] = date("Y-m-d", $first); } } $first = strtotime("+7 day",$first); for($i = 0; $year == date("Y", $first); $i++, $first = strtotime("+7 day",$first)) { if($group_by_month === false) { $weeks[] = date("Y-m-d", $first); } else { if($m != date("M",$first)) { $m = date("M",$first); } $weeks[$m][] = date("Y-m-d", $first); } } return $weeks; } ?>

« previous php.notes (#114245) next »