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
 Trouble with getdate

Author  Topic 

offspring22
Starting Member

38 Posts

Posted - 2009-10-14 : 16:26:01
I'm trying to calculate a "active days on market" field, or ADOM for short. What I need to do is take today's current date, and subtract the date it was first entered (dateentered).

So I imagine I need to do something with getdate - dateentered, but it's not giving me what i need. Any tips? I just need whole numbers, no decimals, ie 102, 30,9, etc.


I've tried

select (getdate() - DateEntered) as ADOM

but it's giving me results like

1900-11-18 02:49:25.797
1901-04-10 19:08:09.797
1900-02-02 22:42:10.797
1901-01-28 22:54:33.797
1901-02-06 00:07:09.797


A sample of dateentered:

2009-06-18 09:55:15.000
2009-06-18 09:59:44.000
2009-06-18 10:04:10.000
2009-06-26 15:15:39.000
2009-07-21 13:50:29.000
2009-07-22 14:01:48.000

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-10-14 : 16:43:35
Use datediff

select datediff(dd,dateentered,getdate())
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-10-14 : 18:03:49
AND...I read this once...that the real trouble with GetDate()

<rimshot>

...is that you're still left all alone on a Saturday night

</rimshot>




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

offspring22
Starting Member

38 Posts

Posted - 2009-10-16 : 12:45:56
Awesome, works perfectly, thanks!
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-10-16 : 13:06:35
My problem is I'm so focused on DATEPART I forget DATENAME.

Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -