Login   Register  
PHP Classes
elePHPant
Icontem

package Week Start and End Days

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      Week Start and End Days  >  All threads  >  package Week Start and End Days  >  (Un) Subscribe thread alerts  
Subject:package Week Start and End Days
Summary:Week Start - that can be done also more simply
Messages:1
Author:Gemmel
Date:2005-09-30 14:54:38
 

  1. package Week Start and End Days   Reply  
Picture of Gemmel
Gemmel
2005-09-30 14:54:38
// $kw = Week Number
if(!$kw) { $kw = date( "W", time() ); }

// Example

$tag0=datefromweek(2005,$kw+1, 0);
echo $tag0[year].".".$tag0[month].".".$tag0[day]." = KW:".$kw."<br>\n";

//
function datefromweek ($y, $w, $o) {

$days = ($w - 1) * 7 + $o;

$firstdayofyear = getdate(mktime(0,0,0,1,1,$y));
if ($firstdayofyear["wday"] == 0) $firstdayofyear["wday"] += 7;
# in getdate, Sunday is 0 instead of 7
$firstmonday = getdate(mktime(0,0,0,1,1-$firstdayofyear["wday"]+1,$y));
$calcdate = getdate(mktime(0,0,0,$firstmonday["mon"], $firstmonday["mday"]+$days,$firstmonday["year"]));

$date["year"] = $calcdate["year"];
$date["month"] = $calcdate["mon"];
$date["day"] = $calcdate["mday"];

return ($date);

} # function datefromweek