note 106363 deleted from function.date by tularis

From: Date: Sun, 12 Feb 2012 11:21:52 +0000
Subject: note 106363 deleted from function.date by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-186074@lists.php.net to get a copy of this message
Note Submitter: martin at eksperimentrum dot dk ---- How to get the week starting date by giving a week number and the year. Monday first day in week <?php function WeekStartDate($week,$year,$format="d-m-Y") { date_default_timezone_set('Europe/Paris'); $firstDayInYear=date("N",mktime(0,0,0,1,1,$year)); if ($firstDayInYear<5) $shift=-($firstDayInYear-1)*86400; else $shift=(8-$firstDayInYear)*86400; if ($week>1) $weekInSeconds=($week-1)*604800; else $weekInSeconds=0; $timestamp=mktime(0,0,0,1,1,$year)+$weekInSeconds+$shift; return date($format,$timestamp); } echo WeekStartDate(44,2011); //result: 31-10-2011 ?>

« previous php.notes (#186074) next »