note 40117 added to function.strftime

From: Date: Sun, 22 Feb 2004 12:51:14 +0000
Subject: note 40117 added to function.strftime
Groups: php.notes 
Request: Send a blank email to php-notes+get-65535@lists.php.net to get a copy of this message
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; } ---- Manual Page -- http://www.php.net/manual/en/function.strftime.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+40117 Delete -- http://master.php.net/manage/user-notes.php?action=delete+40117&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+40117&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#65535) next »