February 4, 2009 at 3:25 am
Hi
How dow I convert this date AUG2007 to 200708.
Select Distinct Replace(Convert(Numeric, [Month], 112), '/', '') as Period
From PTX_TERMINATIONS
I tried this code and several other combinations but I'm not winning.
Please help
February 4, 2009 at 3:52 am
try this:
DECLARE @dt VARCHAR(10)
SELECT @dt = 'AUG2007'
SELECT CONVERT(VARCHAR(6),CAST(LEFT(@dt,3) + ' ' + '01 ' + RIGHT(@dt,4) AS DATETIME), 112) AS DT
/*
DT
------
200708
*/
.
February 4, 2009 at 7:03 am
You don't actually need the day...declare @dt varchar(10)
set @dt = 'AUG2007'
select year(convert(datetime,@dt))*100+month(convert(datetime,@dt)) as period -- int
select convert(char(6),Convert(datetime, @dt), 112) as Period -- char(6)
Derek
February 4, 2009 at 7:18 am
This is the way I would do it, but I am sure there are many more ways:
SELECT CONVERT(CHAR(6),CONVERT(SMALLDATETIME, GETDATE()), 112)
February 4, 2009 at 12:47 pm
[font="Verdana"]Mine would be:
selectconvert(varchar(6), getdate(), 112)
[/font]
February 4, 2009 at 4:03 pm
gary.proctor (2/4/2009)
This is the way I would do it, but I am sure there are many more ways:SELECT CONVERT(CHAR(6),CONVERT(SMALLDATETIME, GETDATE()), 112)
Bruce W Cassidy (2/4/2009)
[font="Verdana"]Mine would be:
selectconvert(varchar(6), getdate(), 112)
[/font]
The only thing is that thatok asked
thatok (2/4/2009)
How dow I convert this date AUG2007 to 200708.
So the key point I was making is that CONVERT will do the conversion without the need for a day number!
Derek
February 4, 2009 at 4:19 pm
[font="Verdana"]Okay. How about:
select convert(varchar(6), convert(datetime, 'AUG2007'), 112)
[/font]
Viewing 7 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply