note 40117 deleted from function.strftime by derick
| From: | derick@php.net | Date: | Sat, 04 Nov 2006 10:43:49 +0000 |
| Subject: | note 40117 deleted from function.strftime by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-119383@lists.php.net to get a copy of this message | ||
Note Submitter: pb at _remove_ pedal dot dk
----
Ever wanted to find the first and last dates in a given week? i.e. you have a week number and a
year, what date has the first and last days in that week respectively? Below is a function that does
just that. You feed it with a week/year and it returns an array with first and last day:
function mk_week_to_dates($week, $year){
//We start some time into prev year
$searchdate = mktime(0,0,0,12,20,$year-1);
//Then we advance $week-1 weeks ahead (no need to search through dates we know won't
give results)
$searchdate = strtotime("+".($week-1)." week",$searchdate);
$found=false;
while ($found==false){
if (date("W",$searchdate) == $week)
$found = true;
else
$searchdate = strtotime("+1 day",$searchdate);
}
$weekdates['firstday'] = $searchdate;
$weekdates['lastday'] = strtotime("+6 day",$searchdate);
return $weekdates;
}