diff --git a/code/widgets/ArchiveWidget.php b/code/widgets/ArchiveWidget.php index 583526f..1f4e65c 100644 --- a/code/widgets/ArchiveWidget.php +++ b/code/widgets/ArchiveWidget.php @@ -51,16 +51,18 @@ class ArchiveWidget extends Widget { $stage = Versioned::current_stage(); $suffix = (!$stage || $stage == 'Stage') ? "" : "_$stage"; + $monthclause = method_exists(DB::getConn(), 'formattedDatetimeClause') ? DB::getConn()->formattedDatetimeClause('"Date"', '%m') . ' * 1' : 'MONTH("Date")'; + $yearclause = method_exists(DB::getConn(), 'formattedDatetimeClause') ? DB::getConn()->formattedDatetimeClause('"Date"', '%Y') : 'YEAR("Date")'; if($this->DisplayMode == 'month') { $sqlResults = DB::query(" - SELECT DISTINCT MONTH(\"Date\") AS \"Month\", YEAR(\"Date\") AS \"Year\" + SELECT DISTINCT $monthclause AS \"Month\", $yearclause AS \"Year\" FROM \"SiteTree$suffix\" INNER JOIN \"BlogEntry$suffix\" ON \"SiteTree$suffix\".\"ID\" = \"BlogEntry$suffix\".\"ID\" WHERE \"ParentID\" IN (" . implode(', ', $ids) . ") ORDER BY \"Year\" DESC, \"Month\" DESC;" ); } else { $sqlResults = DB::query(" - SELECT DISTINCT YEAR(\"Date\") AS \"Year\" + SELECT DISTINCT $yearclause AS \"Year\" FROM \"SiteTree$suffix\" INNER JOIN \"BlogEntry$suffix\" ON \"SiteTree$suffix\".\"ID\" = \"BlogEntry$suffix\".\"ID\" WHERE \"ParentID\" IN (" . implode(', ', $ids) . ") ORDER BY \"Year\" DESC"