在创建事件时,我需要以日期时间格式(0000-00-00 00:00:00
)设置事件开始和事件结束,然后我可以选择设置该事件每周重复到特定日期(0000-00-00
),但我无法在数据库中正确插入重复事件。这就是我所拥有的:
$startDateTime = '2015-04-30 10:30:00';
$endDateTime = '2015-04-30 11:30:00';
$repeatEndDate = '2015-06-01';
$timestamp = strtotime($startDateTime);
$day_of_week = date('l', $timestamp);
$step = 1;
$unit = 'W';
$repeatStart = new DateTime($startDateTime);
$repeatEnd = new DateTime($repeatEndDate);
$repeatStart->modify($day_of_week);
$interval = new DateInterval("P{$step}{$unit}");
$period = new DatePeriod($repeatStart, $interval, $repeatEnd);
foreach ($period as $key => $date ) {
$repeatQuery = 'INSERT INTO event(start,end,status,repeats) VALUES ("'.$startDateTime.'","'.$endDateTime.'","'.$status.'","'.$repeatEndDate.'")';
$repeatResult = mysqli_query($db, $repeatQuery) or die (mysqli_error($db));
}
当我做print_r($date);
的时候,它看起来像这样,没有实际的时间,只有00:00:00
DateTime Object
(
[date] => 2015-04-30 00:00:00
[timezone_type] => 3
[timezone] => Europe/Berlin
)
我知道我不能像那样插入值,但我不知道如何从对象中获得正确的值。因此在本例中,我需要插入从10:30:00开始到11:30:00结束的事件(事件总是在同一天结束),每个星期四从2015-04-30开始,到2015-06-01结束。如何才能做到这一点?
谢谢
https://stackoverflow.com/questions/29958009
复制相似问题