Calculating Trip Duration
(1) By David Jackson (davidjackson) on 2021-07-28 22:58:14 [link] [source]
How can I use a case statement to calculate trip duration?
end_datetime - start_endtime = trip duration. If the trip duration is less than 0 then I want to do: start_endtime - end_datetime = trip duration.
Here is the code I'm trying to use:
Select case when datediff(minute, started_at, ended_at) < 0 then datediff(minute, ended_at, started_at) else datediff(minute, started_at, ended_at) end