'how to calculate time difference over midnight?

I have been stuck on this situation. I need to find time difference between start time and end time. I have tried different methods, but most of the time its either R is not recognising the code or giving me negative times when it passes midnight.

I used this code:

df <-   difftime(com_21$start_time,com_21$end_time, units = "mins")
com_21$ride_length <- df

where com_21 is the name of my data frame.

Data frame:
data frame

Data type using class(): data type using class()

r


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source