February 21, 2006 at 2:08 pm
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
February 21, 2006 at 2:26 pm
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
February 21, 2006 at 3:02 pm
Thanks Krishnan!
That is much cleaner.
Rick-
February 22, 2006 at 7:07 am
or
SELECT STUFF(CONVERT(varchar,GETDATE(),110),3,3,'')
Far away is close at hand in the images of elsewhere.
Anon.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply