Any advice on how to change a date time value in a large table with many rows.
the current datatype is in string format and looks like this in the rows:
23/03/2022 00:00:00
23/03/2022 00:00:00
23/03/2022 00:00:00
23/03/2022 00:00:00
23/03/2022 00:00:00
23/03/2022 00:00:00
I have tried convert
SELECT CONVERT(DATETIME2(7),[start_date] )
FROM 'table_name'
would like to change this to a datetime format, any advice is much appreciated
(n)(var)char
) then you have a design flaw and should be fixing your design to store the data in an appropriate date and time data type.UPDATE dbo.table SET new_col = CONVERT(datetime2(7), old_col, 103);
. The103
is important as it tells SQL Server to interpret it as d/m/y regardless of your language / dateformat settings. I don't think there is going to be a reliable way to convert the existing column to the new type without some kind of transfer, because you can't sayALTER COLUMN <newtype, style number>
. Hopefully this is a good lesson in storing data in the right data type in the first place.