lubridate in R
Parsing by the order of the parts, then arithmetic that respects calendars.
library(lubridate)
days <- ymd(c("2026-07-29", "2026-08-02"))
stamp <- ymd_hms("2026-07-30 09:05:00", tz = "UTC")
print(days)
print(wday(days, label = TRUE))
print(month(days))
print(year(days))
print(floor_date(stamp, "hour"))
print(days + period(1, "month"))
print(days + duration(30, "days"))
print(as.numeric(interval(days[1], days[2]), "days"))
How it works
ymdandymd_hmsname the order they expect.floor_datetruncates to a unit, which is how you group by month.- Periods respect calendars; durations are fixed seconds.
Keywords and builtins used here
cdurationfloor_dateintervallibrarymonthperiodprintwdayyearymdymd_hms
The run, in numbers
- Lines
- 13
- Characters to type
- 351
- Tokens
- 113
- Three-star pace
- 105 tpm
At the three-star pace of 105 tokens a minute, this run takes about 65 seconds.
Step 1 of 2 in Dates & factors, step 8 of 10 in Functional & text tools.