Question

I would like the below select statement to be show as time rather than datetime. I'm aware that a cast as solution is likely however given I am trying to Cast as a "grouped by time", I am not finding a solution.

SELECT 
DATEADD(hour, DATEDIFF(hour, 0,dbo.tbReceiptLine.Time), 0) AS Hourly, 
DATEADD(minute, DATEDIFF(minute, 0, dbo.tbReceiptLine.Time) / 30 * 30, 0) AS [30 Mins]

I would like to show this as time only.

Was it helpful?

Solution

In SQL Server 2008 onwards you can cast to time datatype:

SELECT CAST(dbo.tbReceiptLine.Time as time)

See The ultimate guide to the datetime datatypes

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top