April 13, 2015 at 9:17 am
April 13, 2015 at 9:24 am
Sample data used: -
IF OBJECT_ID('tempdb..#testEnvironment') IS NOT NULL
BEGIN
DROP TABLE #testEnvironment;
END;
SELECT TOP 10
IDENTITY( INT,1,1 ) AS ID,
RAND(CHECKSUM(NEWID())) * 30000 /*(Number of days in range)*/
+ CAST('1945' AS DATETIME) /*(Start date, e.g. '1945-01-01 00:00:00*/ AS randomDateTime
INTO #testEnvironment
FROM master.dbo.syscolumns sc1
CROSS JOIN master.dbo.syscolumns sc2
CROSS JOIN master.dbo.syscolumns sc3;
Actual answer based on sample data: -
SELECT ID,
randomDateTime,
DATEADD(MINUTE, DATEDIFF(MINUTE, 0, randomDateTime) / 15 * 15, 0) AS rounded15
FROM #testEnvironment;
April 13, 2015 at 9:30 am
Thanks .
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply