Hi
I found this code in one of the phpbuilder forums (http://www.phpbuilder.com/board/showthread.php?t=10222903&page=1&pp=15) but can't get my head around why the week is displaying as next week and not the current week!
Th code i'm using is:
<?
function WeekToDate ($week, $year)
{
$Jan1 = mktime (1, 1, 1, 1, 1, $year);
$iYearFirstWeekNum = (int) strftime("%W",mktime (1, 1, 1, 1, 1, $year));
if ($iYearFirstWeekNum == 1)
{
$week = $week - 1;
}
$weekdayJan1 = date ('w', $Jan1);
$FirstMonday = strtotime(((4-$weekdayJan1)%7-3) . ' days', $Jan1);
$CurrentMondayTS = strtotime(($week) . ' weeks', $FirstMonday);
return ($CurrentMondayTS);
}
$iWeekNum = strftime("%U");
$iYear = date("Y");
$sStartTS = WeekToDate ($iWeekNum, $iYear);
echo $sStartDate = date ("F d, Y", $sStartTS)."<br>";
echo $sEndDate = date ("F d, Y", $sStartTS + (6*24*60*60));
?>
Is this something to do with the fact the first day of 2006 was a Sunday? I've tried using %U and %u but it sitll won't give me the current week. I could always do -1 on the weeknum but think this will give me complications next year.
Any ideas?
Thanks
Ant