Intersection of two date interval

From: "Suha Onay" <suhaonay(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Intersection of two date interval
Date: 2007-01-26 09:39:03
Message-ID: 49a67b230701260139n1153ee82x8ae91875118f3cd2@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi,

How can i find the number of days in the intersection of 2 date interval?
For example:
1st interval: (10.01.2007, 20.01.2007)
2nd interval: (13.01.2007, 21.01.2007)
The intersection dates are: 13,14,15,16,17,18,19, 20
The result is: 8

How can i find the result, 8 in an sql query without using CASE statements?

Table columns are id PK, date1 date, date2 date.

Thanks for all your help.

Suha

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tomas Vondra 2007-01-26 09:41:26 implementing (something like) UNIQUE constraint using PL/pgSQL
Previous Message codeWarrior 2007-01-26 02:13:46 Re: LEFT Join Question