Home > OS >  SQL Server : convert multiple different date format in one column
SQL Server : convert multiple different date format in one column

Time:07-05

I have example table with different date format like this :

 | date-column | 
 ------------
 | 20150812    |
 | 03/07/2013  | 
 | 2017-09-23  | 
 |  --Etc--    | 

How to change or convert all the date format? For example I want to change all the date into format yyyymmdd and tried doing so using

CONVERT(VARCHAR, date-column, 112)

CodePudding user response:

This should work:

select CONVERT(VARCHAR(10), cast(date-column as date), 112)

Just take care of the format of your dates if it's dmy or mdy, it should be consistent.

db<>fiddle

CodePudding user response:

This could help you:

update dates
set date-column = cast(date-column as date)

I guess the 'date-column' have type varchar or similar.

  • Related