1

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.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Sesuraj
  • 29
  • 1
  • 2
  • 6
  • you could use the convert function http://stackoverflow.com/questions/4953903/how-can-i-convert-a-sql-server-2008-datetimeoffset-to-a-datetime – Avinash Babu Nov 08 '14 at 15:25

1 Answers1

2

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.

Dan Guzman
  • 43,250
  • 3
  • 46
  • 71