note 87901 added to function.date
| From: | tcross1 at gmail dot com | Date: | Mon, 29 Dec 2008 20:36:08 +0000 |
| Subject: | note 87901 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-148654@lists.php.net to get a copy of this message | ||
a while back i grabbed some code from this page that would generate the range of the current week,
called getWeekRange...
well this week spans 2 years, and it breaks the code... so i re-wrote it. enjoy
#-----------------------------------------------------------------#
# getWeekRange:
function getWeekRange(&$start_date, &$end_date, $week_offset=0) {
$start_date = '';
$end_date = '';
// todays information
list($yr, $mo, $da, $word)
= explode('-', date("Y-m-d-l", strtotime("+".abs($week_offset)."
week")));
// 0 (for Sunday) through 6 (for Saturday)
$day_of_current_week = date('w', strtotime("+".abs($week_offset)."
week"));
// on sunday, they want last week through today.
if ($day_of_current_week == 0){
$day_of_current_week = 7;
}
// calculate day offset to monday and sunday
$days_to_monday = 1 - $day_of_current_week;
$days_to_sunday = 7 - $day_of_current_week;
// set the start and end dates for this week
$start_date = date('Y-m-d', mktime(0, 0, 0, $mo, ($da + ($days_to_monday)), $yr));
$end_date = date('Y-m-d', mktime(0, 0, 0, $mo, ($da + ($days_to_sunday)), $yr));
}
#-----------------------------------------------------------------#
// test it
echo "<pre>";
for ($i=0;$i<=52;$i++){
getWeekRange($start,$end,$i);
echo "[".date("Y-m-d-l",strtotime($start))."]
[".date("Y-m-d-l",strtotime($end))."]\n";
}
echo "</pre>";
#-----------------------------------------------------------------#
outputs:
[2008-12-29-Monday][2009-01-04-Sunday]
[2009-01-05-Monday][2009-01-11-Sunday]
[2009-01-12-Monday][2009-01-18-Sunday]
----
Server IP: 208.69.120.35
Probable Submitter: 167.138.234.19
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- https://master.php.net/note/edit/87901
Del: integrated -- https://master.php.net/note/delete/87901/integrated
Del: useless -- https://master.php.net/note/delete/87901/useless
Del: bad code -- https://master.php.net/note/delete/87901/bad+code
Del: spam -- https://master.php.net/note/delete/87901/spam
Del: non-english -- https://master.php.net/note/delete/87901/non-english
Del: in docs -- https://master.php.net/note/delete/87901/in+docs
Del: other reasons-- https://master.php.net/note/delete/87901
Reject -- https://master.php.net/note/reject/87901
Search -- https://master.php.net/manage/user-notes.php