我怎样才能做oracle相当于:
to_char(date_field, 'YYYY-MM-DD:HH') # e.g. 2012-05-25:19
在 SQL Server 中?
我想要订购栏,这就是我想要的原因year-month-day-hour
我怎样才能做oracle相当于:
to_char(date_field, 'YYYY-MM-DD:HH') # e.g. 2012-05-25:19
在 SQL Server 中?
我想要订购栏,这就是我想要的原因year-month-day-hour
select convert(varchar(10),date_field,120) + ':'+
convert(varchar(2), datepart(hour,date_field))
Unfortunately mssql isn't great at custom date formats. You're stuck with string parsing:
e.g.
select replace(CONVERT(varchar(13),date_field,121),' ',':')
The full details of the formats that are available are here: http://msdn.microsoft.com/en-us/library/ms187928.aspx
Note: If you're lucky enough to be in SQL 2012 you get a new FORMAT
function, which is basically a wrapper of the .Net equivalent: See here: http://msdn.microsoft.com/en-us/library/hh213505.aspx