Using SQL Server 2008 I would like to count the amount of minutes that land between 16:30 and 18:00 for a given date range.
So inputs are for example @fromdate = '2017-04-17 17:00:00' and @todate = '2017-04-19 17:00:00'
So for the above example using lamens maths.
Day 1 (17th) : 60
Day 2 (18th) : 90
Day 3 (19th) : 30
Total 180
Day 1 is 60 because there is 60 minutes between the start date 17:00 and 18:00 Day 2 is 90 because the middle date must be the full 90 minutes between 16:30 and 18:00 Day 3 is 30 because there is 30 minutes between 16:30 and 17:00 (the time of the end date) So I am searching for the ammount of minutes between 16:30 and 18:00 for each day if that makes sense.
I would like the total to be the output.