Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

T-SQL - changing datetime to date data type?

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!

like image 945
dp3 Avatar asked Sep 14 '12 21:09

dp3


People also ask

Can we change date format in SQL?

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.


1 Answers

You will need to ALTER the table:

ALTER TABLE CUSTOMERLIST ALTER COLUMN BirthDate date not null

See Sql Fiddle with demo

like image 90
Taryn Avatar answered Oct 11 '22 18:10

Taryn