In SQL Server, can I do the equivalent of
to_char(date_field, 'YYYY-MM-DD:HH24') in Oracle to get
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
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.
Also, have a look at Pinal Dave's UDF here. It's quite a bit more flexible.
In SQL Server <= 2012 you can say:
In SQL Server 2012 this is much easier; you can say:
SQL fiddle: http://sqlfiddle.com/#!6/72276/5