From 65debb5014f4f1a376ff8e6225cafdeb7ed86f97 Mon Sep 17 00:00:00 2001 From: James Brooks Date: Sat, 2 May 2015 14:57:48 +0100 Subject: [PATCH] Fixes #621 - Use zero-prefixed day formatting. --- app/Models/Metric.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Models/Metric.php b/app/Models/Metric.php index 42c1821a..390f1ddf 100644 --- a/app/Models/Metric.php +++ b/app/Models/Metric.php @@ -91,9 +91,9 @@ class Metric extends Model if (Config::get('database.default') === 'mysql') { if (!isset($this->calc_type) || $this->calc_type == self::CALC_SUM) { - $value = (int) $this->points()->whereRaw('DATE_FORMAT(created_at, "%Y%m%e%H") = '.$dateTime->sub(new DateInterval('PT'.$hour.'H'))->format('YmdH'))->groupBy(DB::raw('HOUR(created_at)'))->sum('value'); + $value = (int) $this->points()->whereRaw('DATE_FORMAT(created_at, "%Y%m%d%H") = '.$dateTime->sub(new DateInterval('PT'.$hour.'H'))->format('YmdH'))->groupBy(DB::raw('HOUR(created_at)'))->sum('value'); } elseif ($this->calc_type == self::CALC_AVG) { - $value = (int) $this->points()->whereRaw('DATE_FORMAT(created_at, "%Y%m%e%H") = '.$dateTime->sub(new DateInterval('PT'.$hour.'H'))->format('YmdH'))->groupBy(DB::raw('HOUR(created_at)'))->avg('value'); + $value = (int) $this->points()->whereRaw('DATE_FORMAT(created_at, "%Y%m%d%H") = '.$dateTime->sub(new DateInterval('PT'.$hour.'H'))->format('YmdH'))->groupBy(DB::raw('HOUR(created_at)'))->avg('value'); } } else { // Default metrics calculations.