使用天数增加日期

时间:2015-03-20 03:58:30

标签: php arrays codeigniter

实际上我的约会是$Date= '03/02/2015';

我想用天数来增加这一天。我的数组是

  Array ( [0] => 1 [1] => 42 [2] => 70 [3] => 98 [4] => 186 [5] => 279 [6] => 372 [7] => 465 [8] => 558 [9] => 730 [10] => 1460 [11] => 4380 [12] => 1825 ).

我将这个数组存储在一个名为$data的变量中。我希望每天都增加日期并打印所有结果日期。我该怎么办?

2 个答案:

答案 0 :(得分:0)

尝试使用此代码可以打印日期

<?php   
    $Date = "2015-02-03";
    $dataArray = Array ( 1 ,42 , 70 , 98 , 186 , 279 ,372);
    foreach($dataArray as $val){
        echo date('Y-m-d', strtotime($Date. " + $val days"))."</br>";
    }
?>

答案 1 :(得分:-1)

使用此代码

<?php

$Date= '03/02/2015';
$stamp= strtotime($Date);

$days=array(42,70,98,186,279,372,465,558,730,1460,4380,1825); //change these values
$values=array();
foreach($days as $day){
   $newstamp=$stamp+($day*24*60*60);
   $values[]=date("m/d/Y",$newstamp);
}

//now add to database
mysql_connect('localhost','user','pass'); //change user pass
mysql_select_db('yourdatabase'); //change here

foreach($values as $value) {
    $sql="insert into yourtable values('".$value."',xxx,xxxx..))"; //change here
    mysql_query($sql);
}

mysql_close();

?>