#Get difference between dates without overlapping.

8 messages · Page 1 of 1 (latest)

oblique epoch
#

Imagine example table:

class Experiance:
    job_title = charfield
    start_date = date time field
    end_date = date time field

Now i want to query sum between every experiance, without overlapping so if 1 date is starting from 2023 ending on 2025, second is starting on 2020 ending on 2024 query should return total experiance of 5 years 😛

nimble aurora
#

Simplest is to just choose the lowest start date and highest end date using the Min and Max db functions.

#

As you can see, this returns a dict with the keys I passed to the aggregate method.

agile topaz
#

Great answer @nimble aurora

oblique epoch
#

That’s not what it want, imagine that in Experiance can have gaps

#

Third row for example have start: 2026 end: 2030, Your query will give us 10years of exp, instead 9