| Function | Description |
|---|---|
Sys.Date()
|
Current Date |
lubridate::today()
|
Current Date |
Sys.time()
|
Current Time |
lubridate::now()
|
Current Time |
lubridate::am()
|
Whether time occurs in am? |
lubridate::pm()
|
Whether time occurs in pm? |
lubridate::leap_year()
|
Check if the year is a leap year? |
## # A tibble: 2,466 x 3
## Invoice Due Payment
## <date> <date> <date>
## 1 2013-01-02 2013-02-01 2013-01-15
## 2 2013-01-26 2013-02-25 2013-03-03
## 3 2013-07-03 2013-08-02 2013-07-08
## 4 2013-02-10 2013-03-12 2013-03-17
## 5 2012-10-25 2012-11-24 2012-11-28
## 6 2012-01-27 2012-02-26 2012-02-22
## 7 2013-08-13 2013-09-12 2013-09-09
## 8 2012-12-16 2013-01-15 2013-01-12
## 9 2012-05-14 2012-06-13 2012-07-01
## 10 2013-07-01 2013-07-31 2013-07-26
## # ... with 2,456 more rows
DatePOSIXctPOSIXlt
| Component | Description |
|---|---|
sec
|
Second |
min
|
Minute |
hour
|
Hour of the day |
mon
|
Month of the year (0-11 |
zone
|
Timezone |
wday
|
Day of week |
mday
|
Day of month |
year
|
Years since 1900 |
yday
|
Day of year |
isdst
|
Daylight saving flag |
gmtoff
|
Offset is seconds from GMT |
R 1.0.0 was released on 2000-02-29 08:55:23 UTC. Save it as
Date using characterDate using origin and numberPOSIXctPOSIXlt and extract
2020-04-19 and ends on 2020-04-2510 days and 2 weeksreceivables.csv data sethr-data.csv data set (use date of hire and termination)
| Specification | Description | Example |
|---|---|---|
%d
|
Day of the month (decimal number) | 12 |
%m
|
Month (decimal number) | 12 |
%b
|
Month (abbreviated) | Dec |
%B
|
Month (full name) | December |
%y
|
Year (2 digit) | 19 |
%Y
|
Year (4 digit) | 2019 |
| %H | Hour | 8 |
| %M | Minute | 5 |
| %S | Second | 3 |
Below, we have specified July 5th, 2019 in different ways. Create the date using as.Date() while specifying the correct format for each of them.
05.07.195-July 2019July 5th, 2019July 05, 20192019-July- 0505/07/201907/05/20197/5/201907/5/192019-07-05
| Date | Specification |
|---|---|
| 19-07-05 |
ymd
|
| 2019-07-05 |
ymd
|
| 05-07-2019 |
dmy
|
| 07-05-2019 |
mdy
|
Below, we have specified July 5th, 2019 in different ways. Parse the dates using strptime() or parse_date_time() or any other helper function.
July-05-19JUL-05-1905.07.195-July 2019July 5th, 2019July 05, 20192019-July- 0505/07/201907/05/20197/5/20192019-07-05
| Function | Description |
|---|---|
year()
|
Get year |
month()
|
Get month (number) |
month(label = TRUE)
|
Get month (abbreviated name) |
month(abbr = FALSE)
|
Get month (full name) |
months()
|
Get month |
week()
|
Get week |
| Function | Description |
|---|---|
day
|
Get day |
mday()
|
Day of the month |
wday()
|
Day of the week |
qday()
|
Day of quarter |
yday()
|
Day of year |
weekdays()
|
Day of week |
days_in_month()
|
Days in the month |
| Function | Description |
|---|---|
hour()
|
Get hour |
minute()
|
Get minute |
second()
|
Get second |
seconds()
|
Number of seconds since 1970-01-01
|
| Function | Description |
|---|---|
quarter()
|
Get quarter |
quarter(with_year = TRUE)
|
Quarter with year |
quarter(fiscal_start = 4)
|
Fiscal starts in April |
quarters()
|
Get quarter |
semester()
|
Get semester |
Let us do some data sanitization. If the due day happens to be February 29, let us ensure that the due year is a leap year. Below are the steps to check if the due year is a leap year:
is_leap which will have be set to TRUE if the year is a leap year else it will be set to FALSEDueis_leapGet the R release dates using r_versions() from the rversions package and tabulate the following
make_date()make_datetime()update()
| Function | Description |
|---|---|
from
|
Starting date of the sequence |
by
|
End date of the sequence |
to
|
Date increment of the sequence |
length.out
|
Length of the sequence |
along.with
|
Use length of this value as length of sequence |
R 2.0.0 was released on 2004-10-04 14:24:38. Create this date using
make_date()make_datetime()2013-04-03 07:12:36 (R 3.0.0 release date)
Let us use intervals to count the number of invoices that were settled within the due date. To do this, we will:
due_next by incrementing the due date by 1 daydue_next and the payment date
Let us use %within% to count the number of invoices that were settled within the due date. We will do this by:
We will explore functions for rounding dates
round_dates()floor_date()ceiling_date()The unit for rounding can be any of the following: