typestar

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

  1. as.Date parses ISO text, or any format.
  2. Subtracting dates gives a difference in days.
  3. format and weekdays render parts for display.

Keywords and builtins used here

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.

Type this snippet

Step 2 of 3 in Text & dates, step 18 of 20 in Language basics.

← Previous Next →

Dates in other languages