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
- How to hide the ID field from the Django admin?
- It is impossible to add a non nullable field without specifying a default. Django error
- ImportError: cannot import name 'url' from 'django.conf.urls' - Django Error
- How to Enable Virtualization in BIOS Security Settings in Intel Processors For Android Studio?
- Dependency 'androidx.activity:activity:1.8.0' requires libraries and applications that depend on it.
- AttributeError: 'NoneType' object has no attribute 'get_text' - Python
- ModuleNotFoundError: No module named 'openpyxl' - Python
- How to get thumbnail from vimeo video URL in Python?
Related Article