I have a column BirthDate
in a table that is using the datetime
data type. Currently, the values resemble the format 1987-12-30 00:00:00.000
.
I would like to update all the rows of this table, changing them to the following format with the date
data type: 1987-12-30
I can run a SELECT...
SELECT CONVERT(date, BirthDate) FROM CUSTOMERLIST
But this is only affecting the display. I would like for it to update the entire column and also change the data type of that attribute as well. Any assistance would be greatly appreciated!
If you are using SQL Server 2012 or above versions, you should use Format() function. With culture option, you can specify date as per your viewers. If you want more date formats of SQL server, you should visit: Custom Date and Time Format.
You will need to ALTER
the table:
ALTER TABLE CUSTOMERLIST ALTER COLUMN BirthDate date not null
See Sql Fiddle with demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With