I have the specified start date time and end date time i.e (end date time is end of sequence), I add a time interval (this can vary) to the start date time in minutes and this gives me the end date time. we can set time interval 15minutes (60 sec*15 min=900sec).
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 |
Post your comments / questions
Recent Article
- ValueError:All arrays must be of the same length - Python
- Check hostname requires server hostname - SOLVED
- How to restrict access to the page Access only for logged user in Django
- Migration admin.0001_initial is applied before its dependency admin.0001_initial on database default
- Add or change a related_name argument to the definition for 'auth.User.groups' or 'DriverUser.groups'. -Django ERROR
- Addition of two numbers in django python
- The request was aborted: Could not create SSL/TLS secure channel -Error in Asp.net
- FieldError: Cannot resolve keyword 'id' into field in Django project
Related Article