Parsing dates with lubridate

Working with Dates and Times in R

Charlotte Wickham

Instructor

ymd()

  • 27th of February 2013
  • ymd() - year, then month, then day
ymd("2013-02-27")
"2013-02-27"
ymd("2013.02.27")
"2013-02-27"
ymd("2013 Feb 27th")
"2013-02-27"
Working with Dates and Times in R

Friends of ymd()

ymd(), ydm(), mdy(), myd(), dmy(), dym()

dmy("27-02-2013")
"2013-02-27"
mdy("02-27-2013")
"2013-02-27"
dmy_hm("27-02-2013 12:12pm")
"2013-02-27 12:12:00 UTC"
Working with Dates and Times in R

parse_date_time(x = ___, order = ___)

parse_date_time("27-02-2013", order = "dmy")
"2013-02-27 UTC"
parse_date_time(c("27-02-2013", "2013 Feb 27th"),
+     order = c("dmy", "ymd"))
"2013-02-27 UTC" "2013-02-27 UTC"
Working with Dates and Times in R

Formatting characters

Character Meaning
d Numeric day of the month
m Month of year
y Year with century
Y Year without century
H Hours (24 hour)
M Minutes
S Seconds
Character Meaning
a Abbreviated weekday
A Full weekday
b Abbreviate month name
B Full month name
I Hours (12 hour)
p AM/PM
z Timezone, offset from UTC
Working with Dates and Times in R

Let's practice!

Working with Dates and Times in R

Preparing Video For Download...