format('Y'); $cm = $now->format('m'); if (!empty($match)) { $ny = $y = $matches[1]; $nm = 1 + $m = $matches[2]; //ignore current month if ($y == $cy && $m == $cm) { continue; } if ($m == 12) { $ny = $y+1; $nm = 1; } $start = new DateTime(); $end = new DateTime(); $start->setDate($y, $m, 1); $end->setDate($ny, $nm, 1); $end->modify('-1 day'); $vstart = $start->format('Y-m-d H:i:s'); $vend = $end->format('Y-m-d H:i:s'); echo "Original period = $y$m, converted to start/stop: $vstart/$vend\n"; $sql2 = "UPDATE $ts SET "; $comma = false; //if ($row['access_start_date'] == '0000-00-00 00:00:00') { $sql2 .= " access_start_date = '$vstart', coach_access_start_date = '$vstart' "; $comma = true; //} //if ($row['access_end_date'] == '0000-00-00 00:00:00') { if ($comma) { $sql2 .= ', '; } $sql2 .= " access_end_date = '$vend', coach_access_end_date = '$vend' "; //} $sql2 .= " WHERE id = ".$row['id']; $res2 = Database::query($sql2); file_put_contents($log,$row['id']."\n",FILE_APPEND); } } }