note 43583 added to function.date
| From: | wicliff at xs4all dot nl | Date: | Sat, 26 Jun 2004 15:12:17 +0000 |
| Subject: | note 43583 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-71785@lists.php.net to get a copy of this message | ||
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
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+43583
Delete -- http://master.php.net/manage/user-notes.php?action=delete+43583&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+43583&report=yes
Search -- http://master.php.net/manage/user-notes.php