Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit ace140662b2c49d1a544e62d4cd230945d56b62d 1 parent 85f084d
Adrian Holovaty authored

Showing 1 changed file with 3 additions and 0 deletions. Show diff stats Hide diff stats

  1. 3  django/core/db/backends/mysql.py
3  django/core/db/backends/mysql.py
@@ -106,6 +106,9 @@ def get_date_trunc_sql(lookup_type, field_name):
106 106
     # http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html
107 107
     # MySQL doesn't support DATE_TRUNC, so we fake it by subtracting intervals.
108 108
     # If you know of a better way to do this, please file a Django ticket.
  109
+    # Note that we can't use DATE_FORMAT directly because that causes the output
  110
+    # to be a string rather than a datetime object, and we need MySQL to return
  111
+    # a date so that it's typecasted properly into a Python datetime object.
109 112
     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)]
110 113
     if lookup_type in ('year', 'month'):
111 114
         subtractions.append(" - interval (DATE_FORMAT(%s, '%%%%e')-1) day" % field_name)

0 notes on commit ace1406

Please sign in to comment.
Something went wrong with that request. Please try again.