I'm trying to move some logic that I have currently within a program and putting it into SQL instead.
My table has the following 3 fields that are of interest to me: StartDate (DateTime), StopDate(DateTime), Length (int)
Length is calculated based on StopDate - StartDate and is expressed to the nearest minute.
What I want to do is query the Db giving a start date and end date and return all records that fall within that date range. I then want to present that data such that the earliest date is set to the start date criteria, the last to the end date criteria and the length recalculated.
Say for example I query for results between 01/02/2015 07:00:00 and 01/02/2015 19:00:00 and I get the following:
Start Stop Length
01/02/2015 06:30:00 01/02/2015 07:05:00
35
01/02/2015 07:05:00 01/02/2015 10:00:00
175
01/02/2015 10:00:00 01/02/2015 19:15:00
555
I would like the output to show as
Start Stop Length
01/02/2015 07:00:00 01/02/2015 07:05:00
5
01/02/2015 07:05:00 01/02/2015 10:00:00
175
01/02/2015 10:00:00 01/02/2015 19:00:00
540
Is there a way to do this?