Ok this is what i have:
function getFirstDayOfWeek($iYear, $iWeekNumber)
{
if ( is_null($iYear) ) $iYear = date('Y');
if ( $iWeekNumber < 10 ) $iWeekNumber = '0'.$iWeekNumber;
$iTime = strtotime($iYear.'W'.$iWeekNumber);
return $iTime;
}
$firstdayofweek = getFirstDayOfWeek($data['year'], $data['week']);
$mDate = date('m', $firstdayofweek);
$dDate = date('d', $firstdayofweek);
$min = mktime(0, 0, 0, $mDate, $dDate, $data['year']);
$max = mktime(23, 59, 59, $dDate, $dDate+6, $data['year']);
Where it later does:
SELECT id
FROM training_activities
WHERE date time >= {$min}
AND time <= {$max}
As you may now until now, the times are saved in unix timestamp.
This code is not working p开发者_StackOverflow社区roperly.
Lets say $data year is 2011 and week 39.
This shows me dates from 26/09-04/10, 8 days, while the week 39 is 29/09 - 02/10
How can i make it select and show weeks right?
The $max
month was using $dDate
instead of $mDate
; the following works:
<?php
function getFirstDayOfWeek($iYear, $iWeekNumber)
{
if ( is_null($iYear) ) $iYear = date('Y');
if ( $iWeekNumber < 10 ) $iWeekNumber = '0'.$iWeekNumber;
$iTime = strtotime($iYear.'W'.$iWeekNumber);
return $iTime;
}
for ($i = 1; $i <= 52; $i++) {
$firstdayofweek = getFirstDayOfWeek(2011, $i);
$mDate = date('m', $firstdayofweek);
$dDate = date('d', $firstdayofweek);
$min = mktime(0, 0, 0, $mDate, $dDate, 2011);
$max = mktime(23, 59, 59, $mDate, ($dDate+6), 2011);
echo date('m/d/Y',$min)." - ".date('m/d/Y',$max)." ($dDate - ".($dDate+6).")\n";
}
?>
http://codepad.org/7hMJQFhq
精彩评论