title: [u"'' value has an invalid format. It must be in YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ] format."]
body: <p>Good day.
  I have a Django views that searches items in the database. The user can search  with email or order number while filtering the database it filters for date.
  If I try to search I get these as error</p>
  
  <blockquote>
    <p>[u"'' value has an invalid format. It must be in YYYY-MM-DD
    HH:MM[:ss[.uuuuuu]][TZ] format."]</p>
  </blockquote>
  
  <p>Here is my views.py</p>
  
  <pre><code>def search_form(request):
  
      if request.method == 'GET':
          user_search = request.GET.get('order')
          print "What is searched for is : ", user_search
  
          start_date = request.GET.get('first_date')
          print "The start date is : ", start_date
  
          end_date = request.GET.get('second_date')
          print "The end date is : ", end_date
  
          if user_search != None or start_date != None or end_date != None:
              items = Order.objects.filter(Q(order_number__iexact=user_search) |
                  Q(client__email__iexact=user_search) |
                  Q(created_on__range=[start_date, end_date])
                  )
              print "items ", items
  </code></pre>
  
  <p>The error is pointing to <code>Q(created_on__range=[start_date, end_date])</code></p>
  
  <p>Traceback:</p>
  
  <pre><code>File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
    149.                     response = self.process_exception_by_middleware(e, request)
  
  File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
    147.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
  
  File "C:\Python27\lib\site-packages\django\contrib\auth\decorators.py" in _wrapped_view
    23.                 return view_func(request, *args, **kwargs)
  
  File "C:\Users\Uchechukwu\Dropbox\Engrs-Shared-Projects\JSA_WEB\jsa_admin\views.py" in search_form
    926.                 Q(created_on__range=[start_date, end_date])
  
  File "C:\Python27\lib\site-packages\django\db\models\manager.py" in manager_method
    122.                 return getattr(self.get_queryset(), name)(*args, **kwargs)
  
  File "C:\Python27\lib\site-packages\django\db\models\query.py" in filter
    790.         return self._filter_or_exclude(False, *args, **kwargs)
  
  File "C:\Python27\lib\site-packages\django\db\models\query.py" in _filter_or_exclude
    808.             clone.query.add_q(Q(*args, **kwargs))
  
  File "C:\Python27\lib\site-packages\django\db\models\sql\query.py" in add_q
    1243.         clause, _ = self._add_q(q_object, self.used_aliases)
  
  File "C:\Python27\lib\site-packages\django\db\models\sql\query.py" in _add_q
    1263.                     current_negated, allow_joins, split_subq)
  
  File "C:\Python27\lib\site-packages\django\db\models\sql\query.py" in _add_q
    1269.                     allow_joins=allow_joins, split_subq=split_subq,
  
  File "C:\Python27\lib\site-packages\django\db\models\sql\query.py" in build_filter
    1203.             condition = self.build_lookup(lookups, col, value)
  
  File "C:\Python27\lib\site-packages\django\db\models\sql\query.py" in build_lookup
    1099.                 return final_lookup(lhs, rhs)
  
  File "C:\Python27\lib\site-packages\django\db\models\lookups.py" in __init__
    19.         self.rhs = self.get_prep_lookup()
  
  File "C:\Python27\lib\site-packages\django\db\models\lookups.py" in get_prep_lookup
    57.         return self.lhs.output_field.get_prep_lookup(self.lookup_name, self.rhs)
  
  File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py" in get_prep_lookup
    746.             return [self.get_prep_value(v) for v in value]
  
  File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py" in get_prep_value
    1440.         value = super(DateTimeField, self).get_prep_value(value)
  
  File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py" in get_prep_value
    1296.         return self.to_python(value)
  
  File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py" in to_python
    1423.             params={'value': value},
  
  Exception Type: ValidationError at /dashboard/search_form/
  Exception Value: [u"'' value has an invalid format. It must be in YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ] format."]
  </code></pre>