DateAdd

  • 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

  • SELECT TYPE,vendor,discontinueddate, datepart(quarter,[discontinueddate]) AS 'Quarter'

    from dbo.EOL

    WHERE DISCONTINUEDDATE > DateAdd(M,-24,GETDATE())

    Order by Discontinueddate

  • 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

  • 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

  • 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

  • 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

     

  • mike - isn't this the same as what is being discussed on this other thread..?!?!

    other thread







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

  • 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.

  • Hey Mike - no one's offended! Just double checking to make sure!







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

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply