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

Convert DD-Mon-YYYY to DD/MM/YYYY Expand / Collapse
Author
Message
Posted Wednesday, October 24, 2012 6:06 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, February 13, 2013 6:23 AM
Points: 20, Visits: 55
I need to convert dt_of_birth [varchar] (15) which is in the format DD-Mon-YYYY to DD/MM/YYYY dt_of _birth is specified in different table and the conversion had to be done and stored in another table which has the same column name as dt_of_birth..

Please help me
Post #1376426
Posted Wednesday, October 24, 2012 7:29 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Thursday, November 6, 2014 1:00 PM
Points: 5,333, Visits: 25,277
If I understand your request correctly, this may be helpful to you

CREATE TABLE #Dob(birth VARCHAR(15))
INSERT INTO #Dob
SELECT '24-10-2012' UNION ALL
SELECT '01-01-2011'
SELECT birth AS 'Input',
REPLACE(birth,'-','/')AS 'Converted' FROM #Dob

Results:
Input Converted
24-10-2012 24/10/2012
01-01-2011 01/01/2011




If everything seems to be going well, you have obviously overlooked something.

Ron

Please help us, help you -before posting a question please read

Before posting a performance problem please read
Post #1376464
Posted Thursday, October 25, 2012 2:21 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, April 1, 2014 3:27 PM
Points: 109, Visits: 957
Wasn't sure about the input format, especially the "-Mon-" segment. Maybe...
DECLARE @Dob TABLE (birth VARCHAR(15))

INSERT INTO @Dob
SELECT '24-Oct-2012'
UNION ALL
SELECT '01-Jan-2011'

SELECT birth AS 'Input'
, CONVERT(VARCHAR(15), CAST(birth AS DATETIME), 103) AS 'Converted'
FROM @Dob

Input Converted
24-Oct-2012 24/10/2012
01-Jan-2011 01/01/2011


(But of course you know you should never store dates as strings, right?)
Post #1377288
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse