note 47207 added to function.mktime

From: Date: Sat, 06 Nov 2004 00:24:03 +0000
Subject: note 47207 added to function.mktime
Groups: php.notes 
Request: Send a blank email to php-notes+get-80184@lists.php.net to get a copy of this message
I was looking for a way to convert a week- and daynumber to a UNIX timestamp. I found Robert Christaanse code below but I found it a bit wordy so I rewrote it to this function: <?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 $offset = ($week-2) * 7 - $firstday + $day; //calc number of days difference from jan 04 return strtotime('+' .$offset .' days', $jan04); } ?> Hope it helps out ;) ---- Manual Page -- http://www.php.net/manual/en/function.mktime.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+47207 Delete -- http://master.php.net/manage/user-notes.php?action=delete+47207&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47207&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47207&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47207&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47207&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47207&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+47207&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#80184) next »