user2687803
user2687803

Reputation: 13

Count days based on couple of date fields in SQL Server

Here is a sample of what I have in my table (SQL Server):

patientID    DateCreated    StartOn      EndOn
---------------------------------------------------
1234         2015-09-16     2015-09-01   2015-09-30   
2345         2015-09-16     2015-09-01   2015-09-30
2346         2015-09-16     2015-09-01   2015-09-30

Currently, it counts the "days" to be 30. So it is really looking at days elapsed between StartOn and EndOn. I want to be able to do this counting based on StartOn and DateCreated. So, in my example the "days" should be 16, that is days elapsed from StartOn to DateCreated.

Upvotes: 1

Views: 73

Answers (2)

AlbertFG
AlbertFG

Reputation: 157

So you can go with:

  Select (EndOn - DateCreated +1) As "Days"
  from Tablename
  where patientID = 1234;

Upvotes: 0

Aladin Hdabe
Aladin Hdabe

Reputation: 865

You can use DateDiff(Day,StartOn,DateCreated)

Upvotes: 1

Related Questions