Dates in R
Parsing, formatting, and doing arithmetic on dates.
start <- as.Date("2026-07-01")
end <- as.Date("2026-07-29")
gap <- as.numeric(end - start)
week_later <- start + 7
sequence <- seq(start, end, by = "week")
label <- format(end, "%d %B %Y")
year <- format(end, "%Y")
weekday <- weekdays(end)
parsed <- as.Date("29/07/2026", format = "%d/%m/%Y")
How it works
as.Dateparses ISO text, or anyformat.- Subtracting dates gives a difference in days.
formatandweekdaysrender parts for display.
Keywords and builtins used here
formatseqweekdays
The run, in numbers
- Lines
- 11
- Characters to type
- 294
- Tokens
- 76
- Three-star pace
- 95 tpm
At the three-star pace of 95 tokens a minute, this run takes about 48 seconds.
Step 2 of 3 in Text & dates, step 18 of 20 in Language basics.