Reputation: 29
I want to convert datetimeoffset(7)
to datetime
in SQL Server.
For example: my datetimeoffset(7)
is: 2014-11-07 00:00:00.0000000 +05:30
I want convert to Datetime
like this: 20141107
(Style 112) without using varchar
.
Upvotes: 1
Views: 5727
Reputation: 46233
i want convert to Datetime like this: 20141107 (Style 112) without using varchar.
Datetime and datetimeoffset data types are stored in SQL Server in binary format. Data representations like '2014-11-07 00:00:00.0000000 +05:30' and '20141107' are in fact strings, so in T-SQL, you must convert to varchar in order to format the data as desired for display purposes so that the client application renders the data as the returned formatted string.
It is generally best to format data for display purposes in the presentation layer instead of T-SQL. Client applications typically have more robust formatting capabilities.
Upvotes: 2