-3

How to get the date and hour information for a given datetime object in Transact-SQL?

E.g. 2014-12-18 21:00:00 for 2014-12-18 21:24:05.

I need to truncate off all parts after the hour - i.e. minutes, seconds, and partial seconds.

Sergey Kalinichenko
  • 697,062
  • 78
  • 1,055
  • 1,465
dingx
  • 1,533
  • 1
  • 18
  • 35
  • 1
    Have you tried anything yourself? If so, show what you tried. If not, please do so before asking for someone here to do it for you. – alroc Dec 18 '14 at 13:48

2 Answers2

1

For SQL Server:

Select DATEPART(HOUR, [date]) + ":" + DATEPART(MINUTE, [date]);

Oracle:

Select TO_CHAR([date], 'HH:MI') From...
AHiggins
  • 6,919
  • 6
  • 35
  • 53
bowlturner
  • 1,898
  • 3
  • 21
  • 35
0
SELECT
CONVERT(TIME,GETDATE()) AS TimeOnly,
CONVERT(DATE,GETDATE(),101) AS DateOnly
GO

Replace the GETDATE() function with whatever you need.

daZza
  • 1,629
  • 1
  • 27
  • 51