Calculating the difference between two times
This recipe is similar to the previous one, but here we'll show how to calculate the difference in time and format the duration appropriately.
By time we mean everything on and beneath the day granularity. What is specific about time is that all periods are proportionally divided. A day has 24 hours, an hour has 60 minutes, and a minute has 60 seconds. On the other hand, the above-day granularity is irregular—days in a month vary throughout the year, and days in the year vary on leap years.
The nice thing about having proportional periods is that we can present the result in various units. For example, we can say that an event lasted for 48 hours but we can also say two days. On the other hand, we can say two days, but we cannot say 0.06 months because a month is not a constant unit of time.
This ability to format time duration in various units will be demonstrated in the following example as well.
Getting ready
The Adventure Works database doesn't...