SQL - Break a start/end time into 15 minute records

Posted by Chu on Stack Overflow See other posts from Stack Overflow or by Chu
Published on 2010-05-27T14:00:24Z Indexed on 2010/05/27 14:11 UTC
Read the original article Hit count: 146

Filed under:
|
|

I've got a record set that consists of a start and end time in two separate fields:

id - Int
startTime - DateTime
endTime - DateTime

I'd like to find a way to query a record and return it as X records based on the number of 15 minute intervals found between the start and end times.

For example, let's say I have a record like this:

id, StartTime, EndTime
1, 1/1/2010 8:28 AM, 1/1/2010 8:47 AM

I would return 3 records, the first would represent the 8:15 interval, #2 for the 8:30 interval and then a 3rd for the 8:45 interval.

I realize this could be done using logic in an sproc, but we are trying to remain db neutral as we support multiple database engines.

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server