Can you convert a Django 'DateField()' to 'date'?

I was using the 'DateField()' in Django, and I wanted to find the time between two dates that are stored in the 'DateField()' field. How can I do this?

This is what I was trying originally: length = datetime.timedelta(start, end)

It gives me this error: TypeError: unsupported type for timedelta seconds component: DateField

The Django DateField represents dates as objects. You can get the timedelta by using regular arithmetic operators: difference = end-start. That will give you a timedelta object, and you can access the days member of that to see how many days are between start and end.

You can just use a django filter {{datetime|data:"d F Y" }} on your template. That code return dd/mm/yyyy date format.

Back to Top