July 27, 2021 at 6:43 pm
i have a formula that calculates the difference between two dates and tells me the hours but instead of giving round in hours, i need hours to be displayed in decimal format. Can someone direct me to the right formula to use?
Delivered = l.ArriveDateTime ,
Weighed = t.TareWeighedDateTime ,
Processed = l.ProcessedDateTime ,
'Wait Time' = DATEDIFF(SECOND, l.ArriveDateTime, l.ProcessedDateTime)/3600,
July 27, 2021 at 8:17 pm
Are you looking for:
Select datediff(minute, '2021-07-01 01:15:00', '2021-07-01 01:30:00') / 60.0
Select datediff(second, '2021-07-01 01:15:00', '2021-07-01 01:30:00') / 60.0 / 60.0
Jeffrey Williams
“We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”
― Charles R. Swindoll
How to post questions to get better answers faster
Managing Transaction Logs
July 27, 2021 at 8:35 pm
If you introduce a decimal type value into the equation, you turn the results from int to decimal. Note the slight difference between the two function calls - one uses 3600 and the other uses 3600.0. Using 3600.0 turns the output to a decimal.
DECLARE @ArriveDateTime datetime = '2021-07-27 09:22:37',
@ProcessedDateTime datetime = '2021-07-27 12:09:14';
SELECT DATEDIFF(SECOND, @ArriveDateTime, @ProcessedDateTime)/3600 AS [Int_Version],
DATEDIFF(SECOND, @ArriveDateTime, @ProcessedDateTime)/3600.0 AS [Decimal_Version];
Int_Version Decimal_Version
----------- ---------------------------------------
2 2.776944
(1 row affected)
Eddie Wuerch
MCM: SQL
July 27, 2021 at 8:47 pm
Thank You
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply