TIME PART FROM DATETIME: This article shows how to get only time part from DateTime in MS SQL Server. While development sometimes we need to take solely Time part from the whole Datetime. That is if the given date value is 2017-01-01 09:32:15.000 and here we want to fetch only time part for this given date that is `09:32` time as result. So mostly we developer do this part with server-side coding by using split function etc. But here we see how to get time part from datetime in MS SQL SERVER using simple query.
select GETDATE() as default_date, cast(DATEPART(HOUR,GETDATE()) as varchar(2))+':'+ cast(DATEPART(MINUTE,GETDATE()) as varchar(4)) as time_part
Get Time part from Datetime in MS SQL server Here we used MS SQL datepart() function to get hours and minutes, and then cast as varchar so we concatenate it, as a result finally we get only time part from given date.
DATEPART() function is used to return a single part of a date/time, such as year, month, day, hour, minute, etc.
In MS Sqlserver 2008 we get the time part from DateTime by using query as follow
select GETDATE() default_date, cast(GETDATE() as time) time_part
Time part from DateTime in ms SQL server 2008