SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Varchar column conversion


Varchar column conversion

Author
Message
mugahjoseph
mugahjoseph
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
Points: 5 Visits: 80
Hi,
I havve a table with a column dateofbirth that is stored as Varchar.
It has values like 02/25/2009, March 23rd 2008, and Wednesday April 2nd 2009.
I need to convert this column to data type datetime.
Any idea that can assist?
Pulivarthi Sasidhar
Pulivarthi Sasidhar
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1678 Visits: 1018
Please look into the following ones

If the varchar contains Day [Mon or tue..etc] or rd/nd/th [2nd ,12th,23rd] it doesnt allow to use cast ...

SELECT CAST ('02/25/2009' as DATETIME)
SELECT CAST ('March 23 2008' as DATETIME)
SELECT CAST ('April 2 2009' as DATETIME)
Tom Brown
Tom  Brown
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1799 Visits: 1488
You may have to strip out the 'nd', 'rd' from April 2nd, April 3rd etc using REPLACE.

See CAST AND CONVERT in MSDN for a full description
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search