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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Calculating days between....

Author  Topic 

offspring22
Starting Member

38 Posts

Posted - 2010-07-29 : 18:41:45
So I'm having a little issue calculating the number of days between when a item was entered, and today's date, minus dayswithdrawn. Dateentered is in the format "2000-03-27 07:04:00.000", and dayswithdrawn is a simple interger "5", or "8" etc.

So I need something to the effect of (todaysdate - dateentered) - dayswithdrawn.... I believe I need to use a getdate for today's date, but I can't seem to get the proper results....

Any suggestions?

jeffw8713
Aged Yak Warrior

819 Posts

Posted - 2010-07-29 : 21:26:06
Is the date actually stored as a datetime data type, or a varchar with the above format?

If it is in a datetime data type, then you can use DATEDIFF:

DATEDIFF(days, GETDATE(), dateentered) - dayswithdrawn

Jeff
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-07-29 : 21:31:27
i assume dateentered is an earlier date right ?

you might want to switch the getdate() and dateentered else you will get negative value

DATEDIFF(DAY, dateentered, GETDATE()) - dayswithdrawn



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -