From add7d31d8b2cc86326ef5f32397844c913d12729 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Tue, 16 Jun 2009 02:57:22 +0000 Subject: [PATCH] BUGFIX: Fixed Sean's MSSQL date fix to work for both Date and Datetime git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@79310 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/model/DataObject.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/core/model/DataObject.php b/core/model/DataObject.php index 3ce3c9497..014a011a2 100644 --- a/core/model/DataObject.php +++ b/core/model/DataObject.php @@ -262,10 +262,19 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity $this->class = get_class($this); foreach($record as $k => $v) { // MSSQLDatabase::date() uses datetime for the data type for "Date" and "SSDatetime" - if($this->db($k) == 'Date' || $this->db($k) == 'SSDatetime') { - $meridiem = substr($v, strlen($v) - 2, strlen($v)); - $v = substr($v, 0, strlen($v) - 6); - $record[$k] = date('Y-m-d H:i:s', strtotime($v . ' ' . $meridiem)); + switch($this->db($k)) { + case "Date": + $meridiem = substr($v, strlen($v) - 2, strlen($v)); + $v = substr($v, 0, strlen($v) - 6); + $record[$k] = date('Y-m-d', strtotime($v . ' ' . $meridiem)); + break; + + case "Datetime": + case "SSDatetime": + $meridiem = substr($v, strlen($v) - 2, strlen($v)); + $v = substr($v, 0, strlen($v) - 6); + $record[$k] = date('Y-m-d H:i:s', strtotime($v . ' ' . $meridiem)); + break; } } }