从当天增加日值

时间:2016-09-06 08:26:02

标签: php arrays timestamp

例如,在我的情况下,我已经有了数组的值......

   array(1) {
   [1]=>
   array(1120) {
    ["2006-02-25"]=>
     array(1) {
      [0]=>
      int(33)
    }
    ["2006-02-20"]=>
    array(1) {
      [0]=>
      int(38)
    }
    ["2006-02-28"]=>
    array(1) {
      [0]=>
      int(46)
    }

结果我得到了这段代码

    $explodeEndDate = explode(" ",$adEndDate);
    $explodeStartDate = explode(" ", $adStartDate);

    $StartDate = $explodeStartDate[0];

    $NewStartDate = strtotime("$explodeStartDate[0]");
    $NewEndDate = strtotime("$explodeEndDate[0]");

    $timeDiff = abs($NewEndDate - $NewStartDate);

    // 86400 seconds in one day
    $NumberDays = $timeDiff/86400;

    //convert into int
    $NumberDays = intval($NumberDays);


    if(array_key_exists($NumberDays, $array[$itemType]) == false){
        $array[$itemType][$StartDate] =[$NumberDays];
    }
}

我想要实现的是,在"$StartDate"值中,例如["2006-02-28"],我想用它的值加上它。如果我们回头看上面的图是例如

["2006-02-25"]=>
    array(1) {
      [0]=>
       int(33)

所以2006-02-2533的加号,结果是2006-04-01。之后,我想在该范围内制作日期

1 个答案:

答案 0 :(得分:0)

如果您想添加日期,请点击此处:

<强>个月:

<?php
$date = date('Y-m-d', strtotime("+33 months", strtotime('2006-02-25')));
var_dump($date)
?>

Demo

<强>天

<?php
$date = date('Y-m-d', strtotime("+33 days", strtotime('2006-02-25')));
var_dump($date)
?>

Demo