Extract Time from Datetime SQL

22,589

Solution 1

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

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

Solution 2

do cast

select cast(datecol as time) [time]
from t
Share:
22,589

Related videos on Youtube

Beanymattd
Author by

Beanymattd

Updated on July 09, 2022

Comments

  • Beanymattd
    Beanymattd almost 2 years

    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.

  • Beanymattd
    Beanymattd over 5 years
    thanks a lot, this is exactly what i needed! Problem solved!