Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Datediff help

Author  Topic 

reedallenbrown
Starting Member

2 Posts

Posted - 2013-01-12 : 12:07:17
I just can't seem to figure this out. I'm trying to get the number of days between two fields. Field one is named "startofcare" and field two is named "dischargeddate". Using the formula below works fine unless the discharge date is blank meaning the Patient has not left service yet. I still need to know the date difference from the startofcare to today. can I do both in one formula?


(datediff(day,[startofcare],[dischargedate]))

I thought I could use (datediff(day,[startofcare],[dischargedate])) .OR. (datediff(day,[startofcare],GETDATE))

but that does not work.

Any idea's????

Thanks so much for the help.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-01-12 : 12:33:06
datediff(day,[startofcare],COALESCE(NULLIF([dischargedate],''),GETDATE()))

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

reedallenbrown
Starting Member

2 Posts

Posted - 2013-01-12 : 12:53:50
Thank you so much that worked !!!!!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-01-12 : 12:57:24
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -