sql - Need part of a date -
i using sql server 2008r2. trying part of date in output, , column in datetime datatype. eg, if current date , time 2016-06-28 17:34:12.060, need output 17:00 hour :00 mins.
i have tried until now,
select datename(hh,substring('2016-06-28 17:34:12.060',12,5)) +':00' which gives me right output.but when pass column name of datetime datatype, gives error,
select datename(hh,substring(timeinhour,12,5)) +':00' gives error,
argument data type time invalid argument 1 of substring function.
i know using substring() @ wrong place, don't know how achieve output. appreciable.i need output hh:00, hour 00 mins.
why use substring() @ all? second argument datename() should date/time data type. so, do:
select datename(hour, '2016-06-28 17:34:12.060') + ':00'
Comments
Post a Comment