Execute the SQL Command:
declare @StartTime datetime = '2016-02-18 09:00:00',
@EndTime datetime = '2016-02-18 18:00:00',
@Interval int = 900 -- this can be changed.;WITH timeSequence AS
(
SELECT
@StartTime AS StartRange,
DATEADD(SECOND, @Interval, @StartTime) AS EndRange
UNION ALL
SELECT
EndRange,
DATEADD(SECOND, @Interval, EndRange)
FROM timeSequence
WHERE DATEADD(SECOND, @Interval, EndRange) < @EndTime
)
SELECT * FROM timeSequence OPTION (MAXRECURSION 0);
StartRange | EndRange |
2/18/2016 9:00:00 AM | 2/18/2016 9:15:00 AM |
2/18/2016 9:15:00 AM | 2/18/2016 9:30:00 AM |
2/18/2016 9:30:00 AM | 2/18/2016 9:45:00 AM |