if (!empty($datestart) && !empty($dateend)) {
$startDate = new DateTime($datestart);
$endDate = new DateTime($dateend);
$dates = array($startDate, $endDate);
$pricesPerMonth = array_pop($stmt->fetchAll(PDO::FETCH_ASSOC));
//echo ($endDate->getTimestamp() - $startDate->getTimestamp())*1000;
$price = 0;
for ($i = $startDate->getTimestamp(); $i <= $endDate->getTimestamp(); $i += 86400) {
$newDate = new DateTime();
$newDate->setTimestamp($i);
$m = $newDate->format('m');
$m = intval($m);
if ($pricesPerMonth[$m]) {
$price += $pricesPerMonth[$m];
}
}
}