Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
dr223
Constraint Violating Yak Guru
444 Posts |
Posted - 2014-06-19 : 10:38:25
|
Hi, I have a column on my table with the varchar(50) datatype. The whole column has the value 2014-04-31I want to Convert the varchar(50)datatype to datetime datatype. The table name is called - dbo.pracsthe column name is - LastDatUpadedThanks in advance.. |
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2014-06-19 : 11:07:14
|
That's an invalid date! (30 days hath September, April....)However, conversion for valid dates is easy:select cast('2014-04-30' as datetime) as mydatetime |
 |
|
dr223
Constraint Violating Yak Guru
444 Posts |
Posted - 2014-06-19 : 11:30:10
|
I want to update the dbo.pracs - column LastDatUpdated with the result. Than I asssume I can easily change the Varchar dataype to datetimePlease help how I can update the table.. Thanks |
 |
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2014-06-19 : 11:33:18
|
You can't convert an invalid date value to a date. So, how do you want to handle invalid date values? |
 |
|
dr223
Constraint Violating Yak Guru
444 Posts |
Posted - 2014-06-19 : 11:36:29
|
Sorry - It's 2014-04-30 |
 |
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2014-06-19 : 11:42:39
|
I understand that you want to:1. Alter the table to change the column LastDatUpaded (is that the real name? seems rather odd!) from varchar(50) to datetime. Is that correct? IF so, this should do the trick:alter table dbo.pracsalter column LastDatUpaded datetime |
 |
|
dr223
Constraint Violating Yak Guru
444 Posts |
Posted - 2014-06-19 : 11:44:13
|
Fantastic... Thank you |
 |
|
|
|
|