typestar

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

  1. ymd and ymd_hms name the order they expect.
  2. floor_date truncates to a unit, which is how you group by month.
  3. Periods respect calendars; durations are fixed seconds.

Keywords and builtins used here

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.

Type this snippet

Step 1 of 2 in Dates & factors, step 8 of 10 in Functional & text tools.

← Previous Next →