Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Varchar column conversion Expand / Collapse
Author
Message
Posted Monday, April 19, 2010 2:44 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Saturday, August 18, 2012 10:37 AM
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?
Post #905771
Posted Monday, April 19, 2010 2:54 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 6:17 AM
Points: 1,059, Visits: 693
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)
Post #905781
Posted Monday, April 19, 2010 3:27 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Saturday, July 26, 2014 3:34 PM
Points: 1,293, Visits: 1,428
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
Post #905792
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse