Jogn Mi Jogn Mi - 19 days ago 5
SQL Question

SQL format date and fetch hour from date

i am new here.

Table Have 'createddate' column with below values.

createddate
2016-11-18 02:30:50.500
2016-11-17 23:31:40.840
2016-11-17 23:07:02.997
2016-11-17 23:02:53.607


i want below output. with HR_Noted column contains hour which mentioned in createddate.

Createddate HR_Noted
2016-11-18 2
2016-11-17 23
2016-11-17 23
2016-11-17 23


thanks in advance.

Answer

Try This.

select cast(createddate as DATE) as createddate, 
       DATEPART(HH , createddate) as HR_Noted  
from   <Your_Table_name>