note 26444 added to function.strftime

From: Date: Thu, 31 Oct 2002 00:53:52 +0000
Subject: note 26444 added to function.strftime
Groups: php.notes 
Request: Send a blank email to php-notes+get-38796@lists.php.net to get a copy of this message
Here's a pair of functions to convert a date to an ISO 8601 year/week and vice versa. function yearweek($date="") { if (!$date) $date = mktime(); $yearweek = strftime("%G%V", $date); return $yearweek; } function dateEndYearweek($yearweek) { $weekEndDay = 0; // 0 = Sunday. $year = (int) substr($yearweek, 0, 4); $week = (int) substr($yearweek, -2, 2); // We know that the 4th Jan is always in week 01, 11th Jan in week 02, ... // so day (4 + (w-1)*7) is in week w. $dayOfYear = 4 + (($week - 1) * 7); $date = mktime(0, 0, 0, 1, $dayOfYear, $year); // Find the last day of this week. $dayOfWeek = date("w", $date); $daysToAdd = ($weekEndDay - $dayOfWeek + 7) % 7; $date += $daysToAdd * 24*60*60; return $date; } -- http://www.php.net/manual/en/function.strftime.php http://master.php.net/manage/user-notes.php?action=edit+26444 http://master.php.net/manage/user-notes.php?action=delete+26444 http://master.php.net/manage/user-notes.php?action=reject+26444

« previous php.notes (#38796) next »