In SQL Server, can I do the equivalent of to_char(date_field, 'YYYY-MM-DD:HH24') in Oracle to get 2012-01-30:23?
Tell me more
×
Database Administrators Stack Exchange is a question and answer site for
database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.
|
|
|||||
|
|
You can use the CONVERT() function and pass it one of the precanned styles. Looks like style 120 (ODBC Canonical) is the closest to what you specifiy. Example:
Also, have a look at Pinal Dave's UDF here. It's quite a bit more flexible. |
|||||||||||
|
|
In SQL Server <= 2012 you can say:
Or
In SQL Server 2012 this is much easier; you can say:
SQL fiddle: http://sqlfiddle.com/#!6/72276/5 |
||||
|
|
|
something like
|
|||||
|
