1

I have to calculate the time difference between to DateTime fields, also keeping in mind to subtract the time frame 10 PM-9 AM for each transaction if it lies in.

The following code snippet saves the duration between those two fields but I'm unable to subtract the time frame 10 PM-9 AM from that duration for further use.

from django.db.models import ExpressionWrapper, DurationField

MyModel.objects.annotate(
     diff=ExpressionWrapper(F('field1') - F('field2'), output_field=DurationField())
)

Can anyone help me to solve this?

  • Could you give examples on what you try to achieve? – ha-neul Dec 08 '20 at 16:12
  • @ha-neul I want to have the time difference for some use cases but this time difference shouldn't contain any time between the range of 10 PM-9 AM. That's why I want to subtract it from the calculated time difference. Now have you got some idea? – Bhirendra Kumar Sahu Dec 08 '20 at 16:42

0 Answers0