对于以下情况,我需要找出2016-12-31之前的哪些日期: 我有一个初始和最后的日期; 我对每条记录都有一个特定的频率;
例如:
motor - $date_ini = 2016-01-01 - $freq = 30 (days)
reductor - $date_ini = 2016-01-01 - $freq = 10 (days)
hidraulic - $date_ini = 2016-01-01 - $freq = 20 (days)
pump- $date_ini = 2016-01-01 - $freq = 10 (days)
I need to record the result in a table for a later consulting:
id01 - motor - 2016-02-01
id02 - motor - 2016-03-01
id03 - motor - 2016-04-01
...
id.. - motor - 2016-12-01
...
id.. - reductor - 2016-01-10
id.. - reductor - 2016-01-20
id.. - reductor - 2016-01-30
...
依旧......
我试过这种方式,但它没有用,给了我一个永恒的循环。
$endDate = "2016-12-31";
$myDates = array();
$finished = false;
while(!$finished){
$quebrarDatasd = explode("-", $result['date_ini']); list($anop, $mesp, $diap) =
$quebrarDatasd;
$lastDate = date('Y-m-d', mktime(0,0,0, $mesp, $diap + $result['freq'], $anop));
if(strtotime($lastDate) > strtotime($endDate)){ $finished = true; break; }
$myDates[] = $lastDate; }
我该怎么办?