Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Date and Time difference

$
0
0

Hi.

I have 2 datetime columns for which I need to find the duration differences.  I need to extract from this how many hours and minutes are between the two values.  I also need to import this data into MS Excel and report on the data using Pivot Tables.

Using DATEDIFF(HOUR, Column1, Column2) I can derive the number of hours.  This is represented as a whole number.  So 58 minutes for example would represent a 0 and 1hr 40 would be a 1. What I would like is if it is 58 minutes, for example, the value represents a numerical value under 1 - .58.  This will allow the user to see the number of minutes rounded up to an hour.  What I am keen to avoid is using minutes in DATEDIFF - as using 360 minutes as six hours would be confusing for the user.

I have also tried CAST(DATEDIFF(MINUTE,  Column1, Column2) / 60.00 AS DECIMAL(18,2)) but this would come up as a 0.9 for 58 minutes.

Any help on this would be greatly appreciated.

Thanks in advance.


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>