note 27865 modified in function.strftime by nicos
| From: | nicos@php.net | Date: | Sun, 05 Jan 2003 19:05:55 +0000 |
| Subject: | note 27865 modified in function.strftime by nicos | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-41693@lists.php.net to get a copy of this message | ||
I am truly sorry - I contributed with a script to overcome the missing %V for Windows-users. It
contained a serious flaw, that prohibited in some cases. Below is a script, that should work in all
cases. I have tested it on most outer cases, e.g. 2005/12/31 and 2006/01/01.
function ISOWeek($y, $m, $d)
{
$week=strftime("%W", mktime(0, 0, 0, $m, $d, $y));
$dow0101=getdate(mktime(0, 0, 0, 1, 1, $y));
$next0101=getdate(mktime(0, 0, 0, 1, 1, $y+1));
if ($dow0101["wday"]>1 &&
$dow0101["wday"]<5)
$week++;
if ($next0101["wday"]>1 &&
$next0101["wday"]<5 &&
$week==53)
$week=1;
if ($week==0)
$week = ISOWeek($y-1,12,31);
return(substr("00" . $week, -2));
}
Regards
--was--
I am truly sorry - I contributed with a script to overcome the missing %V for Windows-users. It
contained a serious flaw, that prohibited in some cases. Below is a script, that should work in all
cases. I have tested it on most outer cases, e.g. 2005/12/31 and 2006/01/01.
function ISOWeek($y, $m, $d)
{
$week=strftime("%W", mktime(0, 0, 0, $m, $d, $y));
$dow0101=getdate(mktime(0, 0, 0, 1, 1, $y));
$next0101=getdate(mktime(0, 0, 0, 1, 1, $y+1));
if ($dow0101["wday"]>1 &&
$dow0101["wday"]<5)
$week++;
if ($next0101["wday"]>1 &&
$next0101["wday"]<5 &&
$week=53)
$week=1;
if ($week==0)
$week = ISOWeek($y-1,12,31);
return(substr("00" . $week, -2));
}
Regards
http://www.php.net/manual/en/function.strftime.php