query($sQuery)) { foreach ($oStatement as $aRow) { $iStart = $aRow[0]; $iEnd = $aRow[1]; break; } $oStart = new DateTime(); $oStart->setTimeStamp($iStart); $oEnd = new DateTime(); $oEnd->setTimeStamp($iEnd); if ($oStart->diff($oEnd)->format('%a') > 1) { $sStart = $oStart->format('Y-m-d'); $sEnd = $oEnd->format('Y-m-d'); printf(" from %s to %s\n", $sStart, $sEnd); $aYaml['end_date'] = $sEnd; $sNewFile = sprintf('%s/%s', $sNewDir, $sBasename); $sNewContents = '---' . "\n" . yamlDump($aYaml) . '---' . "\n" . trim($sContents); file_put_contents($sNewFile, $sNewContents); echo " new file saved!\n"; } } else { echo "Not found!\n"; } } function yamlDump($aData) { return str_replace("'", null, Yaml::dump($aData, 4, 2)); }