note 61488 deleted from function.date by bobby

From: Date: Thu, 07 Sep 2006 17:47:41 +0000
Subject: note 61488 deleted from function.date by bobby
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-116849@lists.php.net to get a copy of this message
Note Submitter: rob at robmacdonald dot com ---- This function takes a YEARWEEK value (most commonly returned from mysql) and examines it to get the start date and end date for the given YEARWEEK. May be of use to someone... function findWeekPeriod($yearweek){ $aPeriod = array(); $year = substr($yearweek,0,4); $week = substr($yearweek,4,2); $startDay = Mon; $endDay = Sun; $startdate = strtotime('+' . $week . ' week',mktime(0,0,0,1,1,$year)); $enddate = $startdate; while(date("D",$startdate) != $startDay){ $startdate = mktime(0,0,0,date("m",$startdate),date("d",$startdate)-1, date("Y",$startdate)); } while(date("D",$enddate) != $endDay){ $enddate = mktime(0,0,0,date("m",$enddate),date("d",$enddate)+1, date("Y",$enddate)); } return array('start' => date('l d/m/y', $startdate), 'end' => date('l d/m/y', $enddate)); return $aPeriod; }

« previous php.notes (#116849) next »