2017-06-15 13 views
0
<?php 
    $today = "2017-06-14"; 
    $prev = "1994-06-01"; 
    $date = $prev + //keep on adding 60 days till june,2017 
    echo '<br>' .$date; 
?> 

また、このような日付をデータベースで1000件更新したいと考えています。私は、効率的で、時間の節約方法が必要ですか?x日を前日に追加して正確な日付を見つける

+0

数学はここで働いてます私はこの発生を公開するデモを設定しています。 diff b/w 2の日付を見つけ、そのdiffを分割します。あなたのセットに基づいて:ex:today-prev = diff; diff/number_of_setがあなたのxになります – Santosh

+0

各エントリごとに毎日または最終日にしますか? –

+0

最終日、つまり最近の日付はどうなりますか? –

答えて

0

これはどうやってやろうとしています...しかし、2017年に60日間の増分が6月を超えるとどうなりますか?

コード(Demo):

$today=strtotime('today'); 
//$min=strtotime('first day of this month'); 
$max=strtotime('last day of this month'); 

$prevs=['1994-06-01','1994-06-7','1994-06-14','1994-06-15','1994-06-17','1994-06-21','1994-06-30']; 
foreach($prevs as $prev){ 
    echo "prev = ",$prev = strtotime($prev),"\n"; 
    echo "diff = ",$diff=$today-$prev,"\n"; // calculate seconds between two dates 
    // add just enough seconds (in 60 day increments) to reach at least $min 
    echo "newseconds = ",$newseconds=$prev+5184000*ceil($diff/5184000),"\n"; // 60 days in seconds 
    if($newseconds>$max){echo "Warning: new incremented date not in input month\n";} // handle this exception? 
    echo "newdate = ",date("Y-m-d",$newseconds),"\n\n"; 
} 

出力:

prev = 770454000 
diff = 727056000 
newseconds = 1501398000 
Warning: new incremented date not in input month 
newdate = 2017-07-30 

prev = 770972400 
diff = 726537600 
newseconds = 1501916400 
Warning: new incremented date not in input month 
newdate = 2017-08-05 

prev = 771577200 
diff = 725932800 
newseconds = 1502521200 
Warning: new incremented date not in input month 
newdate = 2017-08-12 

prev = 771663600 
diff = 725846400 
newseconds = 1502607600 
Warning: new incremented date not in input month 
newdate = 2017-08-13 

prev = 771836400 
diff = 725673600 
newseconds = 1497596400 
newdate = 2017-06-16 

prev = 772182000 
diff = 725328000 
newseconds = 1497942000 
newdate = 2017-06-20 

prev = 772959600 
diff = 724550400 
newseconds = 1498719600 
newdate = 2017-06-29 
関連する問題