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.
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.
For SQL Server:
Select DATEPART(HOUR, [date]) + ":" + DATEPART(MINUTE, [date]);
Oracle:
Select TO_CHAR([date], 'HH:MI') From...
SELECT
CONVERT(TIME,GETDATE()) AS TimeOnly,
CONVERT(DATE,GETDATE(),101) AS DateOnly
GO
Replace the GETDATE()
function with whatever you need.