sql calculating minutes for two dates between two times

Viewed 9830

I have a table with two DateTimes (StartDateTime, EndDateTime) and I want to calculate the minutes between the two.

Now, I know to use the DATEDIFF() function to get this, but I only want to get the number of minutes that fall between two TIME(0) values.

For example:

  StartDateTime     | EndDateTime         | TimeStart | TimeEnd
2017-06-01 03:00:00 | 2017-06-01 23:00:00 | 06:00:00  | 20:00:00

For the above example, I would get: DATEDIFF(minute, StartDateTime, EndDateTime) = 1200.

However, I want to only get the number of minutes that fall between TimeStart and TimeEnd, which would be 840.

How can I write my query to get this?

1 Answers
Related