October 24, 2012 at 6:06 am
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
October 24, 2012 at 7:29 am
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-201224/10/2012
01-01-201101/01/2011
October 25, 2012 at 2:21 pm
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-201224/10/2012
01-Jan-201101/01/2011
(But of course you know you should never store dates as strings, right?)
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply