Avatar of Fred
Fred
Flag for United States of America asked on

How can I convert a column that is varchar(50) to Date time

I want to convert a table column to DATETIME, I used alter table name [Dim_Loan] alter column LoanDate datetime, got an error, Conversion failed when converting date and/or time from character string . The column LoanDate is varchar(13), LoanDate column  has this output Jan 11 2020 1, am not sure what the 1 stands for. The Loan Date is being used in a store procedure  as a  Report Date with datetime as its data type
Microsoft SQL ServerSQL

Avatar of undefined
Last Comment
Scott Pletcher

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Scott Pletcher

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Fred

ASKER
I updated the column now it shows Loan Date Jan 11 2020 but Alter column LoanDate datetime  throws " Conversion failed when converting date and/or time from character string" The statement has been terminated.
Fred

ASKER
Not sure what happened earlier but now it works, I had scrolled down the table and notice some rows had the 1 so I updated the whole table again,
2020-01-14 is the new data type,
Fred

ASKER
the first update went halfway down the table am not sure why, but I scrolled down the table and noticed some rows still had the 1, I updated the table and was able to convert the Loan Date column to date, am curious what this means '[A-Z][a-z][a-z] [0-9]%[2][0-9][0-9][0-9]%'
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Scott Pletcher

What the pattern means is the characters must be:

letter

letter

letter

space

number

<any number of any type of chars> [to allow for Jan 1 yyyy and Jan 11 yyyy, just in case a single-digit day is allowed]

'2'

number

number

number

<any number of any type of chars>