SDU Tools: Time Periods Between in SQL Server T-SQL

As part of our free SDU Tools for developers and DBAs, we have a function that generates dimension columns for individual time periods. To make that easy to use across a range of times in day, we've added a function called TimePeriodsBetween.

It's a table-valued function that takes three parameters:

@StartTime time is the first time to return
@EndTime is the last time to be returned
@MinutesPerPeriod is the number of minutes in each time period for the day (e.g. it's 15 for every quarter of an hour)

For each time period, it returns a key (an incrementing number for the position of the time period within the entire day), and the time.

You can use our tools as a set or as a great example of how to write functions like these.

Find out more

You can see it in action in the main image above, and in the video here:

Access to SDU Tools is one of the benefits of being an SDU Insider, along with access to our other free tools and eBooks. Please just visit here for more info:


Leave a Reply

Your email address will not be published. Required fields are marked *