Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


DateAdd


DateAdd

Author
Message
Mike-238404
Mike-238404
SSC Rookie
SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)

Group: General Forum Members
Points: 29 Visits: 1

Trying build this some that it will return 24 months from the current day. What am I doing wrong??

SELECT TYPE,vendor,discontinueddate, datepart(quarter,[discontinueddate]) AS 'Quarter'
from EOL
WHERE DISCONTINUEDDATE <DateAdd("M",24,GETDATE())
and (DISCONTINUEDDATE = '01/01/2005')
Order by Discontinueddate

Thanks


Ninja's_RGR'us
Ninja's_RGR'us
One Orange Chip
One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)

Group: General Forum Members
Points: 25609 Visits: 9671
SELECT TYPE,vendor,discontinueddate, datepart(quarter,[discontinueddate]) AS 'Quarter'
from dbo.EOL
WHERE DISCONTINUEDDATE > DateAdd(M,-24,GETDATE())
Order by Discontinueddate
Mike-238404
Mike-238404
SSC Rookie
SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)

Group: General Forum Members
Points: 29 Visits: 1

For some reason that makes it go from 2003 - 2009

I need current day plus 24 months so I can show 8 quarters of info at a time.

Thanks for the help.

Mike


SQLBill
SQLBill
SSCarpal Tunnel
SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)

Group: General Forum Members
Points: 4255 Visits: 1068

You say it goes from 2003 to 2009.

Run this:
SELECT GETDATE()

That will show you what the server's date is set as. If you are getting 2009, it looks like your system date is off.

Note that Remi's suggestion does NOT have the quotes around the M in the DATEADD function, where yours did. Remi's is the correct way of doing it. If you want 24 months earlier than GETDATE(), use the -24 otherwise make it 24.

-SQLBill





Ninja's_RGR'us
Ninja's_RGR'us
One Orange Chip
One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)

Group: General Forum Members
Points: 25609 Visits: 9671
SELECT TYPE,vendor,discontinueddate, datepart(quarter,[discontinueddate]) AS 'Quarter'
from dbo.EOL
WHERE DISCONTINUEDDATE > DateAdd(M,-24,GETDATE()) and DISCONTINUEDDATE < DATEADD(D, 1, DATEDIFF(D, 0, GetDate()))
Order by Discontinueddate
Mike-238404
Mike-238404
SSC Rookie
SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)

Group: General Forum Members
Points: 29 Visits: 1

I thought the same thing but it shows the correct date and time. It's my local PC<G>

Still getting a startdate of 2003 -24 and nothing on 24 or +24

The filed is a smalldatetime on SQL 2000 .

If I do WHERE (DISCONTINUEDDATE >= '01/01/2005') I get 01/01/2005 and up correctly as well.

Thanks for all of the help!!

Mike


sushila
sushila
SSCrazy
SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)

Group: General Forum Members
Points: 2989 Visits: 639
mike - isn't this the same as what is being discussed on this other thread..?!?!

other thread







**ASCII stupid question, get a stupid ANSI !!!**
Mike-238404
Mike-238404
SSC Rookie
SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)

Group: General Forum Members
Points: 29 Visits: 1

Yes I was asking the same thing. I though I should start a new thread since it was somthing different.

I appologize if it offended someone.


sushila
sushila
SSCrazy
SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)

Group: General Forum Members
Points: 2989 Visits: 639
Hey Mike - no one's offended! Just double checking to make sure!







**ASCII stupid question, get a stupid ANSI !!!**
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search