Home > database >  lubridate - get hours and minutes from decimal hours
lubridate - get hours and minutes from decimal hours

Time:12-15

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.

CodePudding user response:

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

  • Related