note 47230 deleted from function.mktime by tomsommer

From: Date: Sun, 07 Nov 2004 20:26:45 +0000
Subject: note 47230 deleted from function.mktime by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-80238@lists.php.net to get a copy of this message
Note Submitter: Erik Oskam ---- I found a bug in the code I posted yesterday. Date ("w") returns a zero for a sunday which has to be a 7 when we start counting on monday with a 1. Since 2003 and 2004 have januari 4 on a sunday it didn't appear to me that I corrected this in the $offset variable. For years that don't have jan 4 on a sunday the function returned bogus. The corrected one: <?PHP function datefromweeknr($year, $week, $day) { $jan04 = mktime (0,0,0,01,4, $year); // jan 04 always in week 1 $firstday = date("w", $jan04); // fetch day of week of jan 04 if($firstday == 0) { $firstday = 7; } $offset = ($week-1) * 7 - $firstday + $day; //calc number of days difference from jan 04 return strtotime('+' .$offset .' days', $jan04); } ?>

« previous php.notes (#80238) next »