Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Char to MM/DD/YYYY conversion

Author  Topic 

dim
Yak Posting Veteran

57 Posts

Posted - 2010-07-27 : 14:22:09
Hi,

I have a column which is of data type char(8).

The column values are : 20030212
20030213
20030213

I need to convert the column to MM/DD/YYYY format. I tried with the following approach but it does not work.

SELECT convert(varchar(10),COLUMN, 101) from TABLENAME

But when I do this :
select convert( varchar , getdate(), 101) it works and returns data in MM/DD/YYYY format.

How do I need to convert the char column to represent column data in MM/DD/YYYY format.

Thank You,









Dp

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-07-27 : 14:24:30
You have written
"But when I do this :
select convert( varchar , getdate(), 101) it works and returns data in MM/DD/YYYY format."

So what is the problem?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-07-27 : 14:25:49
Ah!

select convert( varchar(10) , convert(datetime,COLUMN), 101)


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

dim
Yak Posting Veteran

57 Posts

Posted - 2010-07-27 : 16:18:08


Thanks it worked.

Dp
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-07-28 : 03:55:03
welcome


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-07-28 : 07:02:57
Have you read this?
http://beyondrelational.com/blogs/madhivanan/archive/2010/06/29/understanding-datetime-column-part-iv.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -