Reputation: 101
I have a table with a varchar
column (dateandtime
) with date and time in the format dd/mm/yyyy hh:mm:ss
and I need to convert it to a datetime
column.
I have a temp column dateandtimetemp
in the table .
Thanks
Upvotes: 0
Views: 24746
Reputation: 935
Try
SELECT CONVERT(VARCHAR(30),GETDATE(),113) ;
it return result in following format
15 May 2013 16:26:29:850
Upvotes: 2
Reputation: 754268
So then just go ahead and try it!
UPDATE dbo.YourTable
SET DateAndTimeTemp = CAST(DateAndTime AS DATETIME)
and see if it works. If your input data is really always properly defined - you should have no issues here.
This of course depends on what langauge/dateformat setting you have activated in your database - so that might be the first problem you encounter.
If you do have issues, then you can always "clean up" your input data and try again ...
Upvotes: 1
Reputation: 4101
Try this:
SELECT CONVERT(Datetime, '15/05/2013 13:55:12', 104)
It should return : 2013-05-15 13:55:12.000
Upvotes: 4