## Introduction to Business Analytics with R
dstr <- "05/08/2020"
d <- as.Date(dstr, format = "%m/%d/%y")
print(d)
## [1] "2020-05-08"
## Load lubridate and extract information
library(lubridate)
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
d_year <- year(d)
d_month <- month(d)
d_week <- week(d)
d_day <- wday(d)
## Dislay extracted information
print(d_year)
## [1] 2020
print(d_month)
## [1] 5
print(d_week)
## [1] 19
print(d_day)
## [1] 6
## New date
d_25 <- d+25
print(d_25)
## [1] "2020-06-02"
## Check difference
d_time <- difftime(d_25,d)
d_time == 25
## [1] TRUE