Sounds easy right? I want to calculate the difference in hours and minutes between two dates. A good readable notition for my report. I want a format like this:

00:36:53 OR 02:13:45

This can easy be done using a T-SQL Statement like this:

SQL
CONVERT(nvarchar(64), EindDatum-StartDatum, 108) AS Duration

So how does this look like in SQL Server?

T-SQL_Calculate_Difference_In_Minutes_Between_Two_Dates

Frequently asked questions

How do I show the difference between two dates as hours and minutes in SQL Server?

Subtract the dates and convert the result with style 108. For example: CONVERT(nvarchar(64), EindDatum-StartDatum, 108). The output looks like 00:36:53 or 02:13:45.

Which CONVERT style gives hh:mm:ss in T-SQL?

Style 108. Used on the result of EindDatum-StartDatum in a CONVERT to nvarchar(64), it returns a readable duration such as 02:13:45.

What does the duration look like when I use CONVERT with style 108?

It shows hours, minutes and seconds separated by colons, for example 00:36:53. This is a readable notation for a report.

How do I subtract two datetime columns in T-SQL for a duration?

Write EindDatum-StartDatum, with the end date first. Wrap that in CONVERT(nvarchar(64), ..., 108) to turn the result into a time text you can put in a report.

Which data type should I use to store a duration as text in SQL Server?

The example uses nvarchar(64) in the CONVERT call. The result is a text like 00:36:53, which is easy to read in a report.

1 comment

Your email address is not shown. A photo comes from Gravatar, if you have one.

  1. Viral Sarvaiya

    http://codesimplified.com/2013/05/03/find-difference-between-2-dates-in-year-month-day-hour-minute-second-and-millisecond/