February 4, 2004 at 7:02 am
I would think that this should be simple, but I must be overlooking it. I simply what to return a date format of Jan04 from a date field.
Thanks.
fryere
fryere
February 4, 2004 at 8:03 am
select substring(convert(varchar(11), getdate(), 106), 4, 3) + substring(convert(varchar(11), getdate(), 106), 10, 2)
February 4, 2004 at 8:27 am
Thanks Allen,
I had thought about converting it and then chopping it up, but I thought that there maybe something built in that I was overlooking. At Least I won't have to look up how to convert and reassemble. Thanks, it has saved me a lot of time.
fryer
fryere
February 5, 2004 at 1:33 am
I would have done it this way just to cut down on typing - select left(datename(month,getdate()),3) + right(datepart(year,getdate()),2) . Does anyone know which performs better? my execution plan tests prove inconclusive.
February 5, 2004 at 1:54 am
As you can see there are many ways to do this, and here is another:
select replace(convert(varchar(6), getdate(), 107), ' ', '')
February 5, 2004 at 5:55 am
Paul,
Your Code actually returns the Month and Day instead of Month and Year.
Thanks.
fryere
fryere
February 5, 2004 at 7:48 am
My mistake (I was reading your post date....4th of the month), try this instead then:
select replace(right(convert(varchar, getdate(), 6), 6), ' ', '')
February 5, 2004 at 8:06 am
Another possible way to do this would be:
select convert(char(3), getdate(), 107)+convert(char(2),getdate(),11)
Any format that uses the two-year date as the first couple of numbers would work (2,11 or 12)
February 6, 2004 at 6:07 am
Don't forget that BOL (Books On Line) is your best friend!
No shame in looking things up. =;o)
Search for CONVERT to see all available styles 'out of the box' and which to use when building custom displays.
=;o)
/Kenneth
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply