Extracting parts of a datetime

Working with Dates and Times in R

Charlotte Wickham

Instructor

Extracting parts of a datetime

x <- ymd("2013-02-23")
year(x)
2013
month(x)
2
day(x)
23
Working with Dates and Times in R

Extracting parts of a datetime

Function Extracts
year() Year with century
month() Month (1-12)
day() Day of month (1-31)
hour() Hour (0-23)
min() Minute (0-59)
second() Second (0-59)
wday() Weekday (1-7)
yday() Day of year a.k.a. Julian day (1-366)
tz() Timezone
Working with Dates and Times in R

Setting parts of a datetime

x
"2013-02-23"
year(x) <- 2017x
"2017-02-23"
Working with Dates and Times in R

Other useful functions

Function Extracts
leap_year() In leap year (TRUE or FALSE)
am() In morning (TRUE or FALSE)
pm() In afternoon (TRUE or FALSE)
dst() During daylight savings (TRUE or FALSE)
quarter() Quarter of year (1-4)
semester() Half of year (1-2)
Working with Dates and Times in R

Let's practice!

Working with Dates and Times in R

Preparing Video For Download...