#24793: Subtracting DateTime fields in a query expression should use timediff
-------------------------------------+-------------------------------------
     Reporter:  sparkyb              |      Owner:  nobody
         Type:  Uncategorized        |     Status:  new
    Component:  Database layer       |    Version:  1.8
  (models, ORM)                      |   Keywords:  datetime duration
     Severity:  Normal               |  expression
 Triage Stage:  Unreviewed           |  Has patch:  0
Easy pickings:  0                    |      UI/UX:  0
-------------------------------------+-------------------------------------
 If I have a model with start and end DateTime fields, I'd like to be able
 to annotate a query with the duration. For instance, with the model
 {{{
 class Event(Model):
     start_time = DateTimeField()
     end_time = DateTimeField()
 }}}

 I want to be able to do the following query:
 
{{{Event.objects.annotate(duration=ExpressionWrapper(F('end_time')-F('start_time'),output_field=DurationField()))}}}.
 However this yields and incorrect result. At least in MySQL, the proper
 SQL is {{{timediff(end_time,start_time) as duration}}}. I have not found
 an alternate way to do this with Django's ORM without writing SQL.

--
Ticket URL: <https://code.djangoproject.com/ticket/24793>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/050.1d013299d9aea85e40601229db0a94e0%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to