From 39576dd4e0bbdc551c83cd306cdc2534509c2bfd Mon Sep 17 00:00:00 2001 From: Sean Harvey Date: Tue, 18 May 2010 10:47:05 +0000 Subject: [PATCH] BUGFIX MSSQLDatabase date formatting uses style code 120 which represents a typical datetime format without millseconds --- code/MSSQLDatabase.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/code/MSSQLDatabase.php b/code/MSSQLDatabase.php index 611f5a1..a3816d4 100644 --- a/code/MSSQLDatabase.php +++ b/code/MSSQLDatabase.php @@ -1349,7 +1349,7 @@ class MSSQLDatabase extends SS_Database { } /** - * Function to return an SQL datetime expression that can be used with SQLite3 + * Function to return an SQL datetime expression for MSSQL * used for querying a datetime in a certain format * @param string $date to be formated, can be either 'now', literal datetime like '1973-10-14 10:30:00' or field name, e.g. '"SiteTree"."Created"' * @param string $format to be used, supported specifiers: @@ -1363,7 +1363,6 @@ class MSSQLDatabase extends SS_Database { * @return string SQL datetime expression to query for a formatted datetime */ function formattedDatetimeClause($date, $format) { - preg_match_all('/%(.)/', $format, $matches); foreach($matches[1] as $match) if(array_search($match, array('Y','m','d','H','i','s','U')) === false) user_error('formattedDatetimeClause(): unsupported format character %' . $match, E_USER_WARNING); @@ -1409,7 +1408,7 @@ class MSSQLDatabase extends SS_Database { } /** - * Function to return an SQL datetime expression that can be used with SQLite3 + * Function to return an SQL datetime expression for MSSQL. * used for querying a datetime addition * @param string $date, can be either 'now', literal datetime like '1973-10-14 10:30:00' or field name, e.g. '"SiteTree"."Created"' * @param string $interval to be added, use the format [sign][integer] [qualifier], e.g. -1 Day, +15 minutes, +1 YEAR @@ -1424,7 +1423,6 @@ class MSSQLDatabase extends SS_Database { * @return string SQL datetime expression to query for a datetime (YYYY-MM-DD hh:mm:ss) which is the result of the addition */ function datetimeIntervalClause($date, $interval) { - $trans = array( 'year' => 'yy', 'month' => 'mm', @@ -1446,11 +1444,11 @@ class MSSQLDatabase extends SS_Database { } else if(preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/i', $date)) { $date = "'$date'"; } - return "LEFT(CONVERT(VARCHAR, DATEADD(" . $trans[strtolower($matches[2])] . ", " . (int)$matches[1] . ", $date), 121), 19)"; + return "LEFT(CONVERT(VARCHAR, DATEADD(" . $trans[strtolower($matches[2])] . ", " . (int)$matches[1] . ", $date), 120), 19)"; } /** - * Function to return an SQL datetime expression that can be used with SQLite3 + * Function to return an SQL datetime expression for MSSQL. * used for querying a datetime substraction * @param string $date1, can be either 'now', literal datetime like '1973-10-14 10:30:00' or field name, e.g. '"SiteTree"."Created"' * @param string $date2 to be substracted of $date1, can be either 'now', literal datetime like '1973-10-14 10:30:00' or field name, e.g. '"SiteTree"."Created"'