note 88675 deleted from function.date by derick

From: Date: Sun, 22 Mar 2009 18:44:06 +0000
Subject: note 88675 deleted from function.date by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-152291@lists.php.net to get a copy of this message
Note Submitter: SchAtyA ---- A function I have just written to get the first and last date of the week (which is identified by the given date) <?php function weekStartEnd($date) { $dateArr=explode("-",$date); //1-7 , monday-sunday $dayInWeekNo=date("N", mktime(0, 0, 0, $dateArr[1],$dateArr[2],$dateArr[0])); $weekStartEndPosition=array( 1=>array("start"=>0,"end"=>6), 2=>array("start"=>-1,"end"=>5), 3=>array("start"=>-2,"end"=>4), 4=>array("start"=>-3,"end"=>3), 5=>array("start"=>-4,"end"=>2), 6=>array("start"=>-5,"end"=>1), 7=>array("start"=>-6,"end"=>0) ); $weekStart=date("Y-m-d", mktime(0,0,0,$dateArr[1], $dateArr[2]+ $weekStartEndPosition[$dayInWeekNo]["start"], $dateArr[0])); $weekEnd=date("Y-m-d", mktime(0,0,0,$dateArr[1], $dateArr[2]+ $weekStartEndPosition[$dayInWeekNo]["end"],$dateArr[0])); return array("start"=>$weekStart,"end"=>$weekEnd); } ?>

« previous php.notes (#152291) next »