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


Convert DD-Mon-YYYY to DD/MM/YYYY


Convert DD-Mon-YYYY to DD/MM/YYYY

Author
Message
arthi.anan
arthi.anan
SSC-Enthusiastic
SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)

Group: General Forum Members
Points: 152 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
bitbucket-25253
bitbucket-25253
SSCoach
SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)

Group: General Forum Members
Points: 15651 Visits: 25280
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
ACinAZ
ACinAZ
Old Hand
Old Hand (373 reputation)Old Hand (373 reputation)Old Hand (373 reputation)Old Hand (373 reputation)Old Hand (373 reputation)Old Hand (373 reputation)Old Hand (373 reputation)Old Hand (373 reputation)

Group: General Forum Members
Points: 373 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?)
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