Dates to quarters

  • I am trying to break down a date field into quarter and group by years. I can order by dates but I am having no luck find a howto on quarters. Any hint tips out there?

     

    many thanks

     

    Mike

  • Try researching DATEPART(quarter, DATEx) in BOL....



    Good Hunting!

    AJ Ahrens


    webmaster@kritter.net

  • Thanks!

     

    SELECT TYPE,vendor,discontinueddate, datepart(quarter, GETDATE()) AS 'Quarter'

    from EOL

    WHERE (DISCONTINUEDDATE >= '01/01/2005')

    Order by discontinueddate

     

    works and returns the Current quarter but how do I change the GETDATE to cover all years 2005 and above?

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

    from EOL

    WHERE (DISCONTINUEDDATE >= '01/01/2005')

    Order by Discontinueddate

    Works!!!

     

  • what if I need the quarters always 24 months from today everyday?

    I tried using the DateAdd("m",24,Now());

     

    But no luck

     

    Hints??

  • use getdate() instead of now(). and no need to quote the mm

     

    select DateAdd(mm,24,getdate())

  • or..just to take the tedium out of all this...

    select DateAdd(yy, 2, getdate())







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

Viewing 7 posts - 1 through 6 (of 6 total)

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