note 56886 added to function.date

From: Date: Sun, 18 Sep 2005 17:33:44 +0000
Subject: note 56886 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-95370@lists.php.net to get a copy of this message
This quick function will take any input date and based on the start of week ($weekStart) you choose it will find the week that this date falls into and spits out an array of each date for that week. <?php function getWeekDates($someDate) { $weekStart = 0; // 0 = sunday, 1 = monday, etc... $check = strtotime($someDate); while (date("w",$check) <> $weekStart) { $check -= 86400; } $stDate = date("Y-m-d",$check); $weekDates[0] = date("Y-m-d", strtotime("$stDate")); $weekDates[1] = date("Y-m-d", strtotime("$stDate +1 days")); $weekDates[2] = date("Y-m-d", strtotime("$stDate +2 days")); $weekDates[3] = date("Y-m-d", strtotime("$stDate +3 days")); $weekDates[4] = date("Y-m-d", strtotime("$stDate +4 days")); $weekDates[5] = date("Y-m-d", strtotime("$stDate +5 days")); $weekDates[6] = date("Y-m-d", strtotime("$stDate +6 days")); return $weekDates; } // end getWeekDates function $weekDates = getWeekDates("2005-09-29"); echo $weekDates[0].'<br>'; echo $weekDates[1].'<br>'; echo $weekDates[2].'<br>'; echo $weekDates[3].'<br>'; echo $weekDates[4].'<br>'; echo $weekDates[5].'<br>'; echo $weekDates[6].'<br>'; ?> The above example using 2005-09-29 will spit out.... 2005-09-25 2005-09-26 2005-09-27 2005-09-28 2005-09-29 2005-09-30 2005-10-01 Cheers, Kev. ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+56886 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56886&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56886&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56886&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56886&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56886&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+56886&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56886&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+56886&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#95370) next »