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

Getdate and Datepart Expand / Collapse
Author
Message
Posted Tuesday, February 21, 2006 2:08 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, March 26, 2008 7:57 AM
Points: 16, Visits: 2

Hello All,

I'm looking for options on using getdate. What I'm trying to get from getdate () is

01-2006

On the fly my first thought was:

set @v_reportdate = getdate() -21

set @v_GetMoYear = CAST (DATEPART(MM, @v_reportdate)AS VARCHAR) + '-' + CAST (DATEPART(YY, @v_reportdate)AS VARCHAR)

This works and returns 1-2006. Any other options are welcome.

Thanks,

Rick

Post #260398
Posted Tuesday, February 21, 2006 2:26 PM
SSC-Enthusiastic

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

Group: General Forum Members
Last Login: Saturday, October 6, 2012 10:44 AM
Points: 133, Visits: 286

declare @year char(4),@month char(2)

set @year=convert(char(4),getdate(),120)

set @month=right(convert(char(7),getdate(),120),2)

select @month + '-' + @year

 



-Krishnan
Post #260402
Posted Tuesday, February 21, 2006 3:02 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, March 26, 2008 7:57 AM
Points: 16, Visits: 2

Thanks Krishnan!

That is much cleaner.

Rick-

Post #260421
Posted Wednesday, February 22, 2006 7:07 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 9:51 AM
Points: 6,954, Visits: 7,074

or

SELECT STUFF(CONVERT(varchar,GETDATE(),110),3,3,'')




Far away is close at hand in the images of elsewhere.

Anon.

Post #260592
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse