note 56886 deleted from function.date by derick
| From: | derick@php.net | Date: | Mon, 19 Sep 2005 06:42:59 +0000 |
| Subject: | note 56886 deleted from function.date by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-95396@lists.php.net to get a copy of this message | ||
Note Submitter: kevin at barrens dot ca
----
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.