Beanymattd
Beanymattd

Reputation: 129

Extract Time from Datetime SQL

I want to get only Time from a DateTime column using SQL query using SQL Server 2012:

The datetime format in the column at the moment is:

dd/mm/yyyy hh:mm

example - 16/10/2018 11:50

I want to extract the hh:mm and convert the column to a time format (hh:mm or hh:mm:ss)

Any assistance would be much appreciated.

Thanks.

Upvotes: 9

Views: 37176

Answers (2)

Gordon Linoff
Gordon Linoff

Reputation: 1269763

If the column is a string, do you simply want this?

select convert(time, right(col, 5))

Upvotes: 7

Zaynul Abadin Tuhin
Zaynul Abadin Tuhin

Reputation: 31993

do cast

select cast(datecol as time) [time]
from t

Upvotes: 12

Related Questions