好的,这就是我所拥有的:
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']);
以后的地方:
SELECT id
FROM training_activities
WHERE date time >= {$min}
AND time <= {$max}
正如您现在所知,时间保存在unix时间戳中。
此代码无法正常运行。
让我们说数据年份是2011年和第39周。
这显示我的日期为26 / 09-04 / 10,8天,而第39周是29/09 - 02/10
如何让它选择并显示几周?
答案 0 :(得分:1)
$max
个月正在使用$dDate
而不是$mDate
;以下作品:
<?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";
}
?>