[1] "character"
EDS 221 Day 8 PM
Dates and times
August 19th, 2026
Why dates are tricky
Dates look like plain text, but they aren’t — "01/02/2017" could mean January 2nd or February 1st depending on where you’re reading from.
A character string has no concept of “one day later.” A proper date type does.
Parsing dates: ymd(), mdy(), dmy()
lubridate’s parsing functions are named for the order the year, month, and day appear in your text — they all return the same kind of date.
Parsing datetimes: ymd_hms()
Add _hms, _hm, or _h to also capture a time of day. Unspecified time components default to zero.
Extracting components
Once something is a date, you can pull out any piece of it — useful for grouping and filtering.
Date arithmetic
Dates support arithmetic directly. days(), weeks(), and friends add a fixed span of calendar time.
[1] "2026-08-20"
[1] "2026-09-02"
Time difference of 128 days
The last line returns a difftime — the number of days between two dates.
What to memorize
Dates and datetimes are a distinct type from text — parse early, and let lubridate handle the arithmetic.
ymd() (and permutations)ymd_hms() (and permutations)year(), month(), day(), wday()hour(), minute(), second()