question

arti avatar image
arti asked

how to update a Sting mmddyyyy format to YYYYMMDD format in sql. the column name is DOB and i want to update the dob column to YYYYMMDD format

how to update a Sting mmddyyyy format to YYYYMMDD format in sql. the column name is DOB and i want to update the dob column to YYYYMMDD format

format
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Jeff Moden avatar image
Jeff Moden answered

Unless you change the column datatype to something character based, which would be one of the biggest mistakes you'll ever make, you can't change the format of the underlying DATE, DATETIME, or DATETIME2() column. You CAN, however, change what is view in a SELECT. Lookup the CONVERT function in the Microsoft documentation for T-SQL.. If someone suggests it, DO NOT USE THE FORMAT FUNCTION!!!! It's usually at least 43 times slower than the CONVERT function.

I also suggest you bookmark and study the article because the CONVERT function has a huge number of uses including frequent use for formatting dates and times.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.