r0berts
r0berts

Reputation: 946

lubridate - get hours and minutes from decimal hours

I have decimal hours in format 245.85 equalling to 245:51:00 in [hh]:mm:ss format.

I want to transform the decimal hours to hh:mm format, but how do I do it?

the original calculation that renders 245.85 is:

library(lubridate)
time_length(hm("7 27")*33,unit = "hours")

what I want is 245:51 or 245:51:00
If I use as.period I get days too - like in:

as.period(dhours(time_length(hm("7 27")*33,"hours")))
[1] "10d 5H 51M 0S"

and for background - my aim is to multiply hours and minutes (e.g. 7:27) by an arbitrary integer (e.g. 33) and get result back in hh:mm format - avoiding days (as in as.period example above). Say if a piece of work takes 7 hours and 27 minutes and we give me 33 pieces of such work to do per year, it should take me about this many work hours (and minutes) to do.

Upvotes: 1

Views: 1303

Answers (1)

user15175276
user15175276

Reputation:

If it's really only the H:M:S format that gives you trouble, try

library(hms)
hms(hours=245.85)

which yields 245:51:00

Upvotes: 2

Related Questions