-1

I have

CustID Contract start contract ends 100 2013-09-30 2013-12-31
100 2014-02-28 2014-12-31

The calculation should give me the Gaps in days between contracts

I am trying to do the below which gives me the Contract duration:

SELECT CustID , StartDt , EndDt , FIRST_VALUE(DateDiff(DAY, StartDt, EndDt)) OVER (PARTITION BY CustID ORDER BY CustID

ROWS BETWEEN 0 PRECEDING AND 1 FOLLOWING) C

FROM tblContracts

However, I need the calculation between the end date of the last contract and the start date of the second contract

Any Suggestions would be really helpfull

Djab79
  • 13
  • 1
  • 6
  • 1
    Please tag the correct rdbms. Is it mysql or sql-server? – Felix Pamittan Jul 31 '17 at 04:41
  • 2
    MySql or SQL Server? tried or not? read [this](https://stackoverflow.com/help/how-to-ask) or didn't? – Sankar Jul 31 '17 at 04:41
  • Possible duplicate of [How to get the number of days of difference between two dates on mysql?](https://stackoverflow.com/questions/2490173/how-to-get-the-number-of-days-of-difference-between-two-dates-on-mysql) – t.niese Jul 31 '17 at 04:50
  • Using of DATEDIFF, you can calculate the date difference. – Dipak Delvadiya Jul 31 '17 at 06:07
  • Once you've figured out which RDBMS you're using, see https://meta.stackoverflow.com/questions/333952/why-should-i-provide-an-mcve-for-what-seems-to-me-to-be-a-very-simple-sql-query – Strawberry Jul 31 '17 at 06:11

2 Answers2

0

use DateDiff MySQL DateDiff Function

FZS
  • 160
  • 1
  • 2
  • 14
0

Hope the below query helps :

 select datediff(day,StartDt,EndDt) from <tablename>;
Aparna
  • 286
  • 1
  • 11