Description Usage Arguments Details Author(s) Examples
formatDate
converts characters or numbers to dates.
is.Date
indicates which elements are Dates.
1 2 3 4 5 6 7 8 9 |
x |
a character or numeric object |
format |
only for character vectors: |
sep |
separator character for date components |
century |
specify either 2000 or 1900 for two-digit years |
dmy
represents dd mm YYYY
format.
In combination with separators from sep
, this can change to
several date formats.
For example, dmy
+ -
convert to
dd-mm-yyyy
format.
Possible conversions
dmy
+ -
>>> dd-mm-yyyy
dmy
+ /
>>> dd/mm/yyyy
mdy
+ /
>>> mm/dd/yyyy
ymd
+ /
>>> yyyy/mm/dd
dby
+ -
>>> dd-JAN-yy
dby
+ /
>>> dd/JAN/yy
Numeric conversions
Origin is set at 1899-12-30
.
Email: dr.myominnoo@gmail.com
Website: https://myominnoo.github.io/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | ## convert strings to dates
x <- c("2019-01-15", "2019-01-20", "2019-01-21", "2019-01-22")
# check if it is a Date format
is.Date(x)
## Not run:
y <- formatDate(x, "Ymd", "-")
# check if it is a Date format
is.Date(y)
y
## another format
x <- c("22-JAN-19", "24-MAR-20")
y <- formatDate(x, "dby", "-")
is.Date(y)
y
## convert numbers to dates
x <- 42705:42710
y <- formatDate(x)
is.Date(y)
y
## get day, month or year
day(y)
month(y)
year(y)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.