Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Dates to quarters Expand / Collapse
Author
Message
Posted Monday, August 29, 2005 9:09 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, October 12, 2005 9:33 AM
Points: 29, Visits: 1

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

Post #214932
Posted Monday, August 29, 2005 9:23 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Friday, July 22, 2011 5:35 AM
Points: 1,758, Visits: 9
Try researching DATEPART(quarter, DATEx) in BOL....



Good Hunting!

AJ Ahrens


webmaster@kritter.net
Post #214941
Posted Monday, August 29, 2005 10:09 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, October 12, 2005 9:33 AM
Points: 29, Visits: 1

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?

Post #214964
Posted Monday, August 29, 2005 10:22 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, October 12, 2005 9:33 AM
Points: 29, Visits: 1

SELECT TYPE,vendor,discontinueddate, datepart(quarter,[discontinueddate]) AS 'Quarter'
from EOL
WHERE (DISCONTINUEDDATE >= '01/01/2005')
Order by Discontinueddate

Works!!!

 

Post #214970
Posted Monday, August 29, 2005 12:49 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, October 12, 2005 9:33 AM
Points: 29, Visits: 1

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

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

But no luck

 

Hints??

Post #215018
Posted Monday, August 29, 2005 2:39 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, January 27, 2014 10:50 AM
Points: 130, Visits: 88

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

 

select DateAdd(mm,24,getdate())

Post #215071
Posted Monday, August 29, 2005 2:44 PM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, August 18, 2014 8:49 AM
Points: 2,553, Visits: 578
or..just to take the tedium out of all this...

select DateAdd(yy, 2, getdate())








**ASCII stupid question, get a stupid ANSI !!!**
Post #215073
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse