Home > database >  Subtract one hour from hms in R
Subtract one hour from hms in R

Time:10-03

How do I subtract one hour from an hms? for example I have

hms("01:00:00")

and I want to convert it in 00:00:00

CodePudding user response:

We can use

library(lubridate)
out <- hms("01:00:00")
out@hour <- out@hour - 1
sprintf("d:d:d", out@hour, out@minute, seconds(out))
[1] "00:00:00"

We may use as.ITime and subtract 3600

 as.ITime("01:00:00") - 3600
[1] "00:00:00"

CodePudding user response:

hms::hms(lubridate::hms("01:00:00") - lubridate::hours(1))
00:00:00
  • Related