How to identify the length of time between two dates in R

If you are finding the length of time (in hours) between two columns of dates in a dataframe:

> df$yourLength <- round(int_length(interval( df$yourStartTime, df$yourEndTIme)) / 60 / 60, digits = 2)
[1] [interval lengths]

… or …

If you are finding the length of time (in hours) between two datetimes in standard text form:

> yourLength = round(int_length(interval(“2020-1-1 12:30:00”, “2020-1-2 2:45:00”)) / 60 / 60, digits = 2)
[1] 14.25

Note: This solution requires the lubridate package.

Explanation:

int_length returns the number of seconds between two dates in an interval. You must divide the number of seconds by 60 to get the number of minutes in the interval and again by 60 to get the number of hours in the interval. You could also get the number of hours by dividing the return value of int_length by 120.

 
0
Kudos
 
0
Kudos

Now read this

How to manually convert an IP address to binary

For IP Address: 182.167.10.48 the complete binary value is: 10110110.10100111.00001010.00110000 Each decimal number in an IP address is represented at a binary octet (8 binary digits). Using the table below for each decimal in the IP... Continue →