Jump to content
vinnyvedi

Conversion of string/text to datetime.

Recommended Posts

I have a column which has more than 10,000 rows with string in the form of 05MAY2006:04:34:00.000000 it is stored as varchar(25). I need to save it as datetime in the same column. I have tried using update tablenameset columnname = (SUBSTRING(columnname,1,2) + '-' + SUBSTRING(columnname,3,3) + '-' + SUBSTRING(columnname,6,4) + ' ' + SUBSTRING(columnname,11,8));and then alter table tablenamealter columnname datetime;but later it shows up the errorMsg 242, Level 16, State 3, Line 1The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.How do I change it any other opinion or any modification for the above query. Please help. Thank you.

Share this post


Link to post
Share on other sites

If that string is a fixed length, use MID and CONCAT to put it into any format you need.

Edited by niche

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...