我明白了:
/**
* current calenderweek
*/
$date = new DateTime();
echo $date->format('W');
/**
* Update Database with current Calenderweek
*/
...
$data = array(
'id' => $result['id'],
'firstname' => $firstname,
'lastname' => $lastname,
'calender_week' => $date->format('W')
);
我基本上将当前的日历周(现在是40)作为整数放入我的数据库中。
现在,有没有办法将此值转换为周开始和结束的日期,在我的情况下,开始日期将是
星期一28.09.2015
结束将是
星期日04.10.2015
答案 0 :(得分:0)
$week = 40;
$year = 2015;
$time = mktime(0,0,0,1,1,$year) + ($week * 7 *24 * 60 * 60);
$time = $time - ((date('N', $time) - 1) * 24 * 60 * 60);
$monday = date('D d-M-Y', $time);
$sunday = date('D d-M-Y', $time + (6 * 24 * 60 * 60));
echo $monday . ' - ' . $sunday;