note 35160 deleted from function.strtotime by sniper

From: Date: Tue, 21 Oct 2003 11:00:08 +0000
Subject: note 35160 deleted from function.strtotime by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-58990@lists.php.net to get a copy of this message
Note Submitter: shadowfaxx@CC.com ---- In the note below by "php_net at evgeny dot ee", the get_monday() function could be simplified by using : strtotime(" monday", $first_date); or strtotime(" first monday", $first_date); instead of: strtotime(" next monday", $first_date) - 604800; As per the GNU date input format (http://www.gnu.org/manual/tar-1.12/html_chapter/tar_7.html), "next" will give you the 2nd occurance from the specified date, in which case you have to subtract 604800 (1 week in seconds) to return to the 1st occurance. Instead of going one week past the required date then coming back to it, just use "first" or the day name itself (in this case 'monday') to arrive at the 1st occurance. function get_monday($week, $year=""){ $first_date = strtotime("1 january ".($year ? $year : date("Y"))); if(date("D", $first_date)=="Mon") { $monday = $first_date; } else { $monday = strtotime("first monday", $first_date); } $plus_week = "+".($week-1)." week"; return strtotime($plus_week, $monday); }

« previous php.notes (#58990) next »