I am trying to figure out how to calculation a total number of period in a year in the database. Take for example, calculating total leaves in a year.
I am using:
Django - 1.11.7
Postgres - 9.4
Here is my models.py:
class Leave(models.Model):
leavedatefrom = models.DateField()
leavedateto = models.DateField()
An Example to illustrate the issue:
leaves taken in 1 year (01/01/2019 - 31/12/2019)
record 1: (leavedatefrom)01/02/2019 - (leavedateto)05/02/2019 ===> 5 days
record 2: (leavedatefrom)10/05/2019 - (leavedateto)12/05/2019 ===> 3 days
Total days = 5 + 3 = 8 days
How can calculate in Django of the number of days of periods in the database in a year ? Basically I want to get 8 days in the example above.