summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2006-03-01 03:17:24 +0000
committerAdrian Holovaty <adrian@holovaty.com>2006-03-01 03:17:24 +0000
commitace140662b2c49d1a544e62d4cd230945d56b62d (patch)
treea3b6a9faf863f603f3883545aea02f5416f1a4dc
parent85f084de39d03df2152661bb3b070623c88daeca (diff)
Added note to mysql backend about DATE_FORMAT not working. Refs #1423
git-svn-id: http://code.djangoproject.com/svn/django/trunk@2450 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/core/db/backends/mysql.py3
1 files changed, 3 insertions, 0 deletions
diff --git a/django/core/db/backends/mysql.py b/django/core/db/backends/mysql.py
index d1a3e7ee12..1a8ce10e81 100644
--- a/django/core/db/backends/mysql.py
+++ b/django/core/db/backends/mysql.py
@@ -106,6 +106,9 @@ def get_date_trunc_sql(lookup_type, field_name):
# http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html
# MySQL doesn't support DATE_TRUNC, so we fake it by subtracting intervals.
# If you know of a better way to do this, please file a Django ticket.
+ # Note that we can't use DATE_FORMAT directly because that causes the output
+ # to be a string rather than a datetime object, and we need MySQL to return
+ # a date so that it's typecasted properly into a Python datetime object.
subtractions = ["interval (DATE_FORMAT(%s, '%%%%s')) second - interval (DATE_FORMAT(%s, '%%%%i')) minute - interval (DATE_FORMAT(%s, '%%%%H')) hour" % (field_name, field_name, field_name)]
if lookup_type in ('year', 'month'):
subtractions.append(" - interval (DATE_FORMAT(%s, '%%%%e')-1) day" % field_name)