检查点是否在start
和extra
之间的好方法。
point = 2010-06-20
start = 2010-06-17
extra = start + "1 week"
任何想法都会很感激。
答案 0 :(得分:1)
查看strtotime - 然后只需比较生成的时间戳:
$start = strtotime('2010-06-20');
$point = strtotime('2010-06-17');
$extra = strtotime('+1 week', $start);
if($start < $point && $extra > $point){
// it's bewtween...
}
答案 1 :(得分:1)
需要PHP 5.3
$period = new DatePeriod(
new DateTime('2010-06-17'),
DateInterval::createFromDateString('+1 day'),
new DateTime('2010-06-17 +1 week')
);
if (in_array(new DateTime('2010-06-20'), iterator_to_array($period))) {
// date is in range
}
手动http://de2.php.net/manual/en/dateperiod.construct.php
我可能会将DatePeriod
类扩展为contains
方法:
class DateRange extends DatePeriod
{
public function contains(DateTime $dateTime)
{
return in_array($dateTime, iterator_to_array($this));
}
}
然后你可以做
$period = new DateRange(
new DateTime('2010-06-17'),
DateInterval::createFromDateString('+1 day'),
new DateTime('2010-06-17 +1 week')
);
if ($period->contains(new DateTime('2011-06-20'))) {
// date is in range
}
答案 2 :(得分:0)
试试这个
$start_timestamp = strtotime('2010-05-17');
$end_timestamp = strtotime(date("Y-m-d", $start_timestamp) . " +1 week");
$point_timestamp = strtotime('2010-16-20');
if ($point_timestamp < $end_timestamp && $point_timestamp > $point_timestamp) {
// Do your work
}