SQL Server Performance

SQL Date Formats

Discussion in 'ALL SQL SERVER QUESTIONS' started by Bobby Keo, Mar 19, 2012.

  1. Bobby Keo New Member

    I am trying to convert a date column in SQL from YYYY-MM-DD to YYYYMMDD. Do I have to create a new table in order for this conversion to take effect? Is there a way I can just have the date reformatted in the same table?
  2. FrankKalis Moderator

    Welcome to the forum!
    What is the underlying data type for the column? If it is DATE or DATETIME already, then you don't have to be concerned about the format in which it is displayed. This is then just a presentational issue for the client showing the data. If it is some kind of string data type, you can reformat this column by running an UPDATE statement against it. Have a look at the available format here: CAST and CONVERT (Transact-SQL)
  3. Bobby Keo New Member

    Thanks Franks, I figured it out.

    Here's what I used:
    DATE_FORMAT(COLUMN_NAME, '%Y%m%d' ) from the table that I am importing from, so that the data is formatted before importing to the new table.
  4. Madhivanan Moderator

    Note that this is only availbe from version 2012 onwards

Share This Page