note 43583 deleted from function.date by kennyt
| From: | kennyt@php.net | Date: | Sun, 18 Jul 2004 17:05:07 +0000 |
| Subject: | note 43583 deleted from function.date by kennyt | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-73496@lists.php.net to get a copy of this message | ||
Note Submitter: wicliff@xs4all.nl
----
just wrote a function which returns an array containing all the dates of the week surrounding the
given day.
parameters:
$today: given day
$output: date() output e.g. "Y-m-d"
$startSunday: boolean whether you want the returning array have sunday as the first (=true) or as
the last (= false) day
<?php
function getWeek($today, $output, $startSunday){
$_input = $today;
$_this_day = date("w", strtotime($today));
$_this_Week = Array();
//for the past,
$j = 0 - $_this_day;
for($i = 0; $i < $_this_day; $i++){
//when we want sunday to be the last instead of the first, simply add a week
if(!$startSunday && $i == 0){
$_this_week[$i] = $j + 7;
} else {
$_this_week[$i] = $j;
}
$j = $j + 1;
}
//today,
$_this_week[$_this_day] = 0;
//and the future
$j = 1;
for($i = $_this_day + 1; $i < 7; $i++){
$_this_week[$i] = $j;
$j = $j + 1;
}
$_arr_days = Array(0 => 'sunday', 1 => 'monday', 2 =>
'tuesday', 3 => 'wednesday', 4 => 'thursday', 5 =>
'friday', 6 => 'saturday');
$_arr_dates = Array();
for($i = 0; $i < 7; $i++){
$_arr_dates[$_arr_days[$i]] = date($output, strtotime("$_input + $_this_week[$i]
days"));
}
return $_arr_dates;
}
?>
perhaps someone can use this too