The below query returns value in this format 2017-11-18 16:00:00.000
How can i return value in hours only
Desired format
16:00:00.000
17:00:00.000
18:00:00.000
Query
SELECT DATEADD(Hour, DATEDIFF(Hour, 0, GetDate()), 0)
The below query returns value in this format 2017-11-18 16:00:00.000
How can i return value in hours only
Desired format
16:00:00.000
17:00:00.000
18:00:00.000
Query
SELECT DATEADD(Hour, DATEDIFF(Hour, 0, GetDate()), 0)
You can convert the value to time
:
SELECT CONVERT(TIME, DATEADD(Hour, DATEDIFF(Hour, 0, GetDate()), 0))
I would be more inclined to write the logic as:
SELECT dateadd(hour, datepart(hour, getdate()), cast('00:00' as time))
There really is no difference . . . just the logic of adding a certain number of hours to '00:00'
seems simpler.