Reputation: 163
The below works for displaying the date, but when writing to the database [in a datetime column] it seems to be getting converted to the default format.
REPLACE(CONVERT(VARCHAR(11),CONVERT(DATETIME,DATE_FIELD),106),' ','-')
Upvotes: 0
Views: 832
Reputation: 1269623
Date/time values in the database are stored in a binary format. They are not stored as strings. This is the right way to store them.
If you want to fetch the data in a particular format, then use the formula when you retrieve them. Or, you can add a computed column:
alter table t
add date_field_ddmonyyyy as (REPLACE(CONVERT(VARCHAR(11), CONVERT(DATETIME,DATE_FIELD), 106), ' ', '-'));
Upvotes: 4